Android 如果我在屏幕外启动它,ImageView 会缩小

Android ImageView is shrinking if I start it offscreen

我正在为 ImageView 设置动画以反映太阳升起的 iOS 应用程序中的功能。如果我在容器 RelativeLayout 下面启动它,它会将我的 ImageView 高度缩小到 marginTop 和 RelativeView 底部之间的差异(在这种情况下,图像显示为 100dp 而不是 290)。它显示了预览中的行为以及设备上的行为。此外,它不会将图像裁剪到相对布局。我怎样才能更好地制作动画?

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:background="@drawable/home_back_morning"
    android:id="@+id/rlTop"
    android:clipChildren="true"
    >
    <ImageView
        android:layout_width="290dp"
        android:layout_height="290dp"
        android:minHeight="290dp"
        android:minWidth="290dp"    
        android:src="@drawable/sun"
        android:id="@+id/ivSun"
        android:layout_marginLeft="-150dp"
        android:layout_marginTop="300dp"
        android:scaleType="centerInside"
        android:cropToPadding="true">    
</RelativeLayout>

//Fragment:
    TranslateAnimation translation;
    translation = new TranslateAnimation(0f, 0F, 0f, -250f);
    translation.setStartOffset(1000);
    translation.setDuration(1000);
    translation.setFillAfter(true);
    translation.setInterpolator(new BounceInterpolator());
    ivSun.startAnimation(translation);

您的代码在模拟器中运行良好。
但再次尝试将 RelativeLayout 更改为 FrameLayout,例如:

<FrameLayout
    android:id="@+id/rlTop"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:background="@drawable/home_back_morning"
    android:clipChildren="true">

    <ImageView
        android:id="@+id/ivSun"
        android:layout_width="290dp"
        android:layout_height="290dp"
        android:layout_marginLeft="-150dp"
        android:layout_marginTop="300dp"
        android:cropToPadding="true"
        android:minHeight="290dp"
        android:minWidth="290dp"
        android:scaleType="centerInside"
        android:src="@drawable/sun"/>
</FrameLayout>