簡體   English   中英

將TextView直接放在XML上的Imageview之上

[英]Placing the TextView directly on top of the Imageview on XML

現在,textview首先垂直顯示,next是imageview。 我怎樣才能使textview疊加在XML的textview之上? textview具有比imageview更高的Z順序。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0px"
android:padding="0px">
<TextView android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#AA000000"
android:textColor="#ffffffff"
android:textSize="22sp" 
android:text="Find Now"
android:enabled="false"
>
</TextView>
 <ImageView
android:id="@+id/myImageView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bar_top"/> 

一種可能的解決方案是刪除表格布局並使用以下代碼:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#AA000000"
android:textColor="#ffffffff"
android:textSize="22sp" 
android:text="Find Now"
android:enabled="false"
>
</TextView>
 <ImageView
android:id="@+id/myImageView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textItem"
android:src="@drawable/bar_top"/> 
</RelativeLayout> 

另一個解決方案,如果您需要表布局用於其他目的是使用framelayout,其內容將是textview和imageview並將其添加為tablelayout的單元格

刪除TableLayout,它應該彼此疊置。 你可以通過很多不同的android:layout_...屬性輕松改變位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM