Placing/Overlapping(Z-Index) a View Above Another View in Android

Placing/Overlapping(z-index) a view above another view in android

You can't use a LinearLayout for this, but you can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example:

<FrameLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_drawable"
android:scaleType="fitCenter"
/>
<TextView>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="5dp"
android:text="My Label"
/>
</FrameLayout>

In this instance, the TextView would be drawn on top of the ImageView, along the bottom center of the image.

Z-index in android?

Your xml does not contain your outer layout, but I assume it is a relative layout. In a RelativeLayout, the elements' z levels are determine by the order they are added to the container. View added later will be on top. Try moving your sliding drawer to the bottom of your outer container. Like this --

<ListView android:id="@+id/listView1">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_above="@+id/InnerRelativeLayout"
android:layout_alignParentTop="true"
/>
<RelativeLayout>
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >

</RelativeLayout>

<com.ltvie.chat.MultiDirectionSlidingDrawer>
xmlns:my="http://schemas.android.com/apk/res/com.ltvie.chat"
android:id="@+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent"
my:handle="@+id/handle"
my:content="@+id/content"
>
<include>
android:id="@id/content"
layout="@layout/pen_content"
android:gravity="top"
/>
<ImageView>
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:src="@drawable/sliding_drawer_handle_bottom" />
</com.ltvie.chat.MultiDirectionSlidingDrawer>

Placing/Overlapping (z-index) a view above actionbar tabs

I finally Removed the tabBar and replaced it with simple buttons to switch between tabs and placed it before CustomLayout in xml to be drawn before it.

<LinearLayout>
....
// tabs layout />

<CustomLayout>

....
/>

Android FrameLayout z-index issue when child is elevated

android:elevation overrides the typical notion of z-indexing in a FrameLayout or RelativeLayout. What you are witnessing is correct behaviour. You can set the elevation of the ImageView to "3dp" and that should give you the expected ordering.

Is it possible to place one view over another in android?

FrameLayouts let you pile each view on top of the one below. This can also be achieved with a RelativeLayout.

Android ConstraintLayout - Put one view on top of another view

Set an elevation on the ProgressBar; 2dp seems to work.

android:elevation="2dp"

You could also try setting translationZ as suggested in the accepted answer to a similar question.

I also came across this answer as an alternative.

how to use z-index in android

A very simple way would be to use a RelativeLayout

<RelativeLayout> 
android:orientation="vertical"
android:layout_width="300dp"
android:layout_height="50dp" >
<ImageView>
android:layout_height="40dp"
android:id="@+id/imageView1"
android:background="@drawable/nicetab"
android:layout_width="300dp" />
<TextView>
style="@style/DialogText.Title"
android:id="@+id/title"
android:paddingBottom="10dip"
android:paddingLeft="45dip"
android:paddingTop="7dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/codeFont"
android:textSize="15dip" />
</RelativeLayout>

How to set z index by using some integer values

there is no Z-index in android layouts. You'll need to use FrameLayout or RelativeLayout if you need to place elements on top of each other in reverse order.

see Placing/Overlapping(z-index) a view above another view in android



Related Topics



Leave a reply



Submit