我想知道如何在ImageView
上使用固定的宽度和高度裁剪具有缩放背景图像的parent
。
基本上,我想使用ImageView android:background
缩放图像,然后裁剪图像超出父级边界的部分。
到目前为止,我有以下代码:
<RelativeLayout android:id="@+id/time_foregrd"
android:layout_width="57px"
android:layout_height="100px"
android:layout_marginLeft="100px"
android:layout_marginTop="285px"
android:clipChildren="true"
>
<ImageView android:layout_width="57px"
android:layout_height="338px"
android:minWidth="57px"
android:minHeight="338px"
android:background="@drawable/time_foreground"
/>
</RelativeLayout>
但这不起作用...我在做什么错?
最佳答案
好的,我设法做到了。我没有使用RelativeLayout
,而是使用了FrameLayout
,并且效果很好。
这是代码:
<FrameLayout android:id="@+id/time_foregrd"
android:layout_width="57px"
android:layout_height="100px"
android:layout_marginLeft="100px"
android:layout_marginTop="285px"
>
<ImageView android:layout_width="57px"
android:layout_height="338px"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="@drawable/time_foreground"
/>
</FrameLayout>