Android overlay outside/between layout boundaries

2019-04-27 01:03发布

I have to add an overlay (ImageView) so that it's a bit shifted to the left of the containing layout's left boundary.

enter image description here

What is the best way to do this?

Tried something simple, like putting the ImageView inside the layout and use negative margin

android:layout_marginLeft="-20dip"

This made this:

enter image description here

(Correction: Text in the image should be 20dip not 20px)

AbsoluteLayout is deprecated. Is there something like z-order? Or what do I do?

Thanks in advance.

Edit: I tried using relative layout instead. Same effect. Here's the xml reduced to a minimum:

<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>

Result enter image description here

Also happens when the containing layout has a background image smaller than the screen instead of padding.

4条回答
男人必须洒脱
2楼-- · 2019-04-27 01:11

Use a transparent(android:background="#00000000") imageview to the left of linear layout with width = 30dp. And make myId as aligning left in case of relative layout. If you are using linear layout make orientation as horizontal and let the transparent imageview be the first entry in it.

查看更多
相关推荐>>
3楼-- · 2019-04-27 01:13

Using RelativeLayout instead of LinearLayout (to allow overlapping) and adding this to the RelativeLayout fixed it:

android:clipToPadding="false"
查看更多
Luminary・发光体
4楼-- · 2019-04-27 01:26

Instead of

android:layout_marginLeft="-30dip"

try with

android:paddingLeft="-30dp"

查看更多
趁早两清
5楼-- · 2019-04-27 01:35

set "android:clipChildren = false" in xml

查看更多
登录 后发表回答