Android覆盖在布局边界之外/之间

时间:2012-04-20 12:59:19

标签: android layout

我必须添加一个叠加层(ImageView),使其稍微偏移到包含布局左边界的左侧。

enter image description here

这样做的最佳方式是什么?

尝试了一些简单的事情,比如将ImageView放在布局中并使用负边距

android:layout_marginLeft="-20dip"

这使得:

enter image description here

(更正:图像中的文字应为20dip而不是20px)

不推荐使用AbsoluteLayout。是否有像z-order这样的东西?或者我该怎么办?

提前致谢。

编辑:我尝试使用相对布局。同样的效果。这里的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 个答案:

答案 0 :(得分:14)

使用RelativeLayout而不是LinearLayout(允许重叠)并将其添加到RelativeLayout修复它:

android:clipToPadding="false"

答案 1 :(得分:1)

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

答案 2 :(得分:1)

而不是

  

机器人:layout_marginLeft = “ - 30dip”

尝试

  

机器人:paddingLeft = “ - 30DP”

答案 3 :(得分:0)

在线性布局的左侧使用透明(android:background =&#34;#00000000&#34;)imageview,宽度= 30dp。并且在相对布局的情况下将myId作为左对齐。如果使用线性布局,请将方向设置为水平,并将透明图像视图作为其中的第一个条目。