2011-12-03 86 views
1

即時使用該代碼;相對佈局不放按鈕

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:text="Button" /> 

</RelativeLayout> 

由於某種原因,這不適用於模擬器與540x960。該按鈕出現在模擬器的中間。

在我的droid2中,它能正常工作。

enter image description here

左圖展示它是如何工作在我的Droid 2的手機,而右側顯示如何是工作在HTC sensationXe模擬器

+0

什麼操作系統版本是模擬器?也許你應該把TextView固定在某個東西上。 –

+1

我已經更新了我的問題,並且我上傳了一些圖片,以便您能夠看到問題 – Yayo28

回答

0

你必須設置錨點您的TextView ..嘗試對齊按鈕左側或右側的文本視圖,問題應該消失。

0

方向屬性不適用於相對佈局。請嘗試以下步驟

<TextView 
    android:id="@+id/helloid" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_below="@id/helloid" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Button" /> 
+0

這不起作用,我已經上傳了一些關於此問題的圖片。 – Yayo28

1

我已經找到問題的答案。我是編譯我的應用程序作爲anddroid 1.5,現在我已將此添加到清單

<uses-sdk android:minSdkVersion="3" 
    android:targetSdkVersion="4" /> 

和我編譯到Android 1.6

現在是它必須是

0

編輯XML的地方通過這個,它會工作。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:gravity="bottom" 
     android:text="Button" /> 

</RelativeLayout>