2013-10-12 57 views
0

我有一个框架布局,其中我有一个列表视图,编辑文本和一个按钮,但现在我想把一个按钮放在列表视图上方布局的右上角,但我面对的是问题。我的xml是:enter image description here在xml中的Android框架布局

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

     <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="86dp" 
    android:layout_gravity="bottom" > 

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

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@+id/button1" 
     android:ems="10" /> 

    </RelativeLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="317dp" > 

    </ListView> 

     </FrameLayout> 
+0

你似乎已经忘了介绍我想在右上角的布局添加按钮,您所遇到的问题, – Kuffs

+0

但我无法做到这一点。 – Talib

+1

你正在寻找的结果的屏幕截图会有所帮助。 – ssantos

回答

1

那么FrameLayouts的设计通常只能容纳一个子元素。它们有点像通配符。所以我会建议使用它如何张贴。相反,使相对布局成为根布局。

这是一个如何做这项工作的例子。

图片:

enter image description here

代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
    <Button 
    android:id="@+id/button2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:text="NEW BUTTON!" /> 

    <ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="317dp" 
    android:layout_below="@+id/button2"> 
    </ListView> 

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

    <EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/list" 
    android:layout_toLeftOf="@+id/button1" 
    android:ems="10" /> 

</RelativeLayout>