Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android overlay outside/between layout boundaries

Tags:

android

layout

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.

like image 465
User Avatar asked Apr 20 '12 12:04

User


2 Answers

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

android:clipToPadding="false"
like image 67
User Avatar answered Sep 20 '22 20:09

User


set "android:clipChildren = false" in xml

like image 29
saarraz1 Avatar answered Sep 22 '22 20:09

saarraz1