我需要添加一个遮罩层(ImageView),使其稍微向左偏移容器布局的左边界。
怎样才能最好地实现这一点?
尝试了一些简单的方法,例如将ImageView放置在布局内并使用负边距。
android:layout_marginLeft="-20dip"
这使得以下结果:
(更正:图片中的文本应该是20dip而不是20px)
AbsoluteLayout已被弃用。是否有类似于z-order的东西?或者我该怎么做?
提前感谢。
编辑:我尝试使用relative layout代替。效果相同。这是减少到最小的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:paddingLeft="50dip"
>
<ImageView
android:id="@+id/myId"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_marginLeft="-30dip"
android:clipChildren="false"
android:src="@drawable/pic" />
</RelativeLayout>
结果
![enter image description here](https://istack.dev59.com/0oNdo.webp)
当包含布局的背景图像小于屏幕而不是填充时,也会发生这种情况。