2011-08-16 100 views
0

我想在屏幕底部有文本視圖,列表視圖和兩個按鈕。 這裏是我的佈局Android:無法在屏幕底部有兩個按鈕

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
android:id="@+id/widget36" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<TextView 
android:id="@+id/textView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="TextView" 
android:gravity="center" 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true"> 
</TextView> 
<ListView 
android:id="@+id/listView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_below="@+id/textView" 
android:layout_alignParentLeft="true" 
> 
</ListView> 
<RelativeLayout 
android:id="@+id/relativeLayout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@color/darkgray" 
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
> 
<Button 
android:id="@+id/doneButton" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Button" 
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:layout_weight="0.5"> 
</Button> 
<Button 
android:id="@+id/cancelButton" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Button" 
android:layout_alignParentTop="true" 
android:layout_alignParentRight="true" 
android:layout_right="@+id/doneButton" 
android:layout_weight="0.5"> 
</Button> 
</RelativeLayout> 
</RelativeLayout> 

你們可以請幫我搞清楚什麼問題>

+0

那麼究竟是什麼問題呢? – ernazm

+0

在我的佈局中,兩個按鈕都重疊:( – user3072848

回答

0

如果你想專門放置物品,你可以嘗試相對於其他物品對準他們。因此,而不是:

android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 

你可以使用:

<Button 
    android:id="@+id/doneButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_weight="0.5"> 
    </Button> 
    <Button 
    android:id="@+id/cancelButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_alignParentBottom="true" 
    android:layout_toRightOf="@+id/doneButton" 
    android:layout_weight="0.5"> 
    </Button> 
0

我已經在你的代碼所做的更改,看看這個:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
android:id="@+id/widget36" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<TextView 
android:id="@+id/textView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="TextView" 
android:gravity="center" 
android:layout_above = "@+id/listView" 
> 
</TextView> 
<ListView 
android:id="@+id/listView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_above="@+id/relativeLayout" 
android:layout_alignParentLeft="true" 
> 
</ListView> 
<RelativeLayout 
android:id="@+id/relativeLayout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#222222" 
android:layout_alignParentBottom="true" 
android:gravity = "center_horizontal"> 
<Button 
android:id="@+id/doneButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Button1" 
android:layout_weight="0.5"> 
</Button> 
<Button 
android:id="@+id/cancelButton" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Button2" 
android:layout_toRightOf="@+id/doneButton" 
android:layout_weight="0.5"> 
</Button> 
</RelativeLayout> 
</RelativeLayout> 
0

你應該設置的android:layout_width爲wrap_content。將這兩個按鈕設置爲fill_parent意味着兩個按鈕都將與屏幕一樣寬。

+0

我希望這兩個按鈕都佔用整個屏幕寬度。 – user3072848

+0

請查看此鏈接:http://groups.google.com/group/android-developers/ msg/c66e677b79ec5f15 – kyrias

1

最有可能你想要這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:id="@+id/widget36" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
> 
    <TextView 
     android:id="@+id/textView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:gravity="center_horizontal" 
    > 
    </TextView> 
    <ListView 
     android:id="@+id/listView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
    > 
    </ListView> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/darkgray" 
    > 
     <Button 
      android:id="@+id/doneButton" 
      android:text="Button" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
     > 
     </Button> 
     <Button 
      android:id="@+id/cancelButton" 
      android:layout_height="wrap_content" 
      android:text="Button" 
      android:layout_width="fill_parent" 
      android:layout_weight="1" 
     > 
     </Button> 
    </LinearLayout> 
</LinearLayout> 
+0

屏幕底部的兩個按鈕並沒有佔用相同的空間 – user3072848

+0

0_0真的嗎?我測試過了,它們是平等的。除了其中一個文本太長而且填充了更多文本比1行還是要讓他們佔用上層空間? – ernazm