1
我對Android開發很陌生,我試圖弄清楚如何使用RelativeLayout標籤來定位我的視圖。我的目標是在左邊有一個大的TextView,在它的右邊有兩個ButtonView,堆疊在一起。這裏是我使用的XML代碼:Android RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wood_tile">
<TextView
android:id="@+id/life_counter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="00" />
<Button android:text="@string/button_up"
android:id="@+id/button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/life_counter"/>
<Button android:text="@string/button_down"
android:id="@+id/button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_up"/>
</RelativeLayout>
我覺得我不能正確使用標籤。有人可以解釋它的工作原理嗎?提前致謝。
謝謝,現在所有的視圖都可見! 至於你的第二部分,我真正想要做的是把所有三個中心,不分別左對齊和右對齊。我必須弄清楚如何做到這一點。 – nathan 2011-04-07 00:43:18
要將它們居中,您需要將它們放置在具有屬性「android:layout_centerInParent =」true「的嵌套RelativeLayout中。請參見[此解決方案](http://stackoverflow.com/questions/1499258/can-we-put -layout-in-the-screen-in-android/1501534#1501534)。 – 2011-04-07 01:02:10
美麗。這是一個很好的單獨來臨。感謝您的幫助! – nathan 2011-04-07 01:14:04