How to use z-index in android

<LinearLayout 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" ></ImageView> <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" /> </LinearLayout> 

How can I put a TextView in an ImageView. Is there a way in android to do this, in HTML it is too easy, we use z-index, but here is no idea

+4
source share
2 answers

A very simple way is to use 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> 
+6
source

The proposed way to make a text view on top of the image view is to use textview drawable.

 android:drawable[Top|Left|Right|Bottom]="@your_drawable_here" <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:drawableTop="@drawable/your_drawable_from_imageview" android:textSize="15dip" /> 

I'm not sure what you have in your style, so if the above does not work, try deleting the style or paste the style here and I will help you.

+2
source

Source: https://habr.com/ru/post/1380568/


All Articles