2012-08-03 48 views
1

有沒有辦法將textview定位在中心的android按鈕上方?我不想爲特定的屏幕顯示硬編碼值,但會動態縮放。該按鈕將始終居中,但...Android的textview定位

在此先感謝!

回答

1

是,如果你的父母佈局是一個RelativeLayout你可以定位在關係視圖彼此還是這裏的家長是一個簡單的例子(警告沒有輸入到這個IDE,可能包含錯字):

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<Button 
android:id="@+id/mBtn" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="I am a Button!" 
android:layout_centerInParent="true" /> 

<TextView 
android:id="@+id/mTxt" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:text"Some Text" 
android:layout_above="@+id/mBtn" /> 

</RelativeLayout> 

這將使您的佈局看起來大致如下:

________________________ 
|      | 
|      | 
|  Some Text  | 
| [I am a Button!] | 
|      | 
|      | 
|______________________| 
+0

完美。非常感謝! – Mobie 2012-08-03 22:45:43