Android布局边界之外/之间的覆盖层

8

我需要添加一个遮罩层(ImageView),使其稍微向左偏移容器布局的左边界。

enter image description here

怎样才能最好地实现这一点?

尝试了一些简单的方法,例如将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

当包含布局的背景图像小于屏幕而不是填充时,也会发生这种情况。

4个回答

14

使用RelativeLayout代替LinearLayout(允许重叠),并将以下内容添加到RelativeLayout中即可解决问题:

android:clipToPadding="false"

1

不要使用

android:layout_marginLeft="-30dip"

尝试使用

android:paddingLeft="-30dp"


1
在xml中设置“android:clipChildren = false”。

1
没有帮助。我把它放在包含布局和图像视图中,但什么也没改变。 - User

0
使用一个透明的 ImageView(android:background="#00000000")放在宽度为30dp的线性布局左侧。如果使用相对布局,请将 myId 对齐到左侧。如果使用线性布局,请将方向设置为水平,并让透明的 ImageView 成为其中的第一项。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接