如何将宽图像(从右到左)设置为活动背景?

时间:2016-12-04 12:38:20

标签: android android-animation

我需要将我的宽图像(1800x1201px)设置为我的活动背景,以便我可以放置应用徽标并在上方登录/注册按钮。

我尝试使用FrameLayoutImageView。动画正在运行,但图像未填满整个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上当前预览的方式: Android Studio preview

我尝试使用layout_heightmatch_parent设置wrap_content,但无法找到正确的scaleType以使其填满屏幕高度并创建从右到左的动画

更新

我为xxx-hdpi设备创建了一个更大的图像(3840x2560),现在预览以我需要的方式显示图像,但是当我运行应用程序时,它在顶部和底部都有空白。

此外,我需要创建一种“回旋镖”动画,所以当图像从右向左移动时,它会从左到右反转动画,依此类推。

更新图片: Updated image

2 个答案:

答案 0 :(得分:0)

android:adjustViewBounds="false"更改为android:adjustViewBounds="true"并使其高度match_parent完成。

答案 1 :(得分:0)