how to use z-index in android

别说谁变了你拦得住时间么 提交于 2020-01-24 04:35:06

问题


  <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


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/8079500/how-to-use-z-index-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!