【问题标题】:how to use z-index in android如何在android中使用z-index
【发布时间】:2013-03-20 23:04:31
【问题描述】:
  <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>

如何将 TextView 放在 ImageView 上。 android有什么办法可以做到这一点,在HTML中我们使用z-index太容易了,但是在这里-不知道

【问题讨论】:

标签: android android-layout


【解决方案1】:

一个非常简单的方法是使用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】:

    在图像视图之上执行文本视图的建议方法是使用文本视图的可绘制对象。

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

    我不确定您的风格有什么,所以如果上面给出的内容不起作用,请尝试删除该风格,或将其粘贴到此处,我会帮助您。

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多