我想知道如何在 parent
上使用固定宽度和高度裁剪具有缩放背景图像的 ImageView
。
基本上,我希望使用 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>
关于java - Android 在父 RelativeLayout 中裁剪 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18341005/