【发布时间】:2016-12-04 12:38:20
【问题描述】:
我需要将我的宽幅图像 (1800x1201px) 设置为我的活动背景,这样我就可以在上方放置应用徽标和登录/注册按钮。
我尝试使用FrameLayout 和ImageView。动画正在运行,但图像没有填满整个 FrameLayout 高度。
活动
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="br.com.myapp.app.activities.SplashActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/splash_bg_image"
android:src="@drawable/splash_background"
android:contentDescription=""
android:scaleType="matrix"
android:adjustViewBounds="false"
android:cropToPadding="false" />
</FrameLayout>
活动类
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
animateBackground();
}
private void animateBackground() {
final ImageView splashImage = (ImageView) findViewById(R.id.splash_bg_image);
splashImage.startAnimation(outToLeftAnimation());
}
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(20000L);
return outtoLeft;
}
}
以下是它目前在 Android Studio 上的预览方式:
我尝试将layout_height 设置为match_parent 和wrap_content,但找不到正确的scaleType 使其填充屏幕高度并创建从右到左的动画。
更新
我为 xxx-hdpi 设备创建了一个更大的图像 (3840x2560),现在预览会以我需要的方式显示图像,但是当我运行应用程序时,它的顶部和底部都有空白。
我还需要创建一种“回旋镖”动画,这样当图像从右向左移动时,它会将动画从左向右反转,依此类推。
【问题讨论】: