Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 could I put TextView on ImageView. Is there any way in android to do this, in HTML it is too easy we ara using z-index, but here - no idea

like image 636
user989340 Avatar asked Nov 10 '11 12:11

user989340


People also ask

What is Z index in Android?

Z-Index for Annotation Stacking Order on Android This means the annotations with a lower z-index will be obscured if the annotations are overlapping. A z-index of 0 means that the annotation is all the way at the back, while the highest z-index means that the annotation is at the front.

What is Z order in Android?

Z order determines how objects lay on each other - that is which one is on top. This is good example for HTML (with example pictures). In android is simpler (that is in my opinion conception is simpler, but usage could be less easy) since there is no explicit z index.

How to use frame layout in Android?

Android Framelayout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen. Generally, we can say FrameLayout simply blocks a particular area on the screen to display a single view.

What is Android TranslationZ?

TranslationZ is a dynamic property used for animation. Basically it's needed to nicely handle elevation changes.


2 Answers

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>
like image 92
Sherif elKhatib Avatar answered Oct 06 '22 00:10

Sherif elKhatib


The suggested way to do the text view on top of an image view is to use the textview's 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 what is given above doesn't work, try removing the style, or paste the style here, and I'll help you out.

like image 33
Jarrett R Avatar answered Oct 06 '22 01:10

Jarrett R