2011-08-16 81 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