jcl*_*ova 74 layout android listview alignment
我想在列表视图的底部有一个按钮.
如果我使用relativeLayout/FrameLayout,它会对齐,但listView会变得非常紧张.
(在底部的按钮后面)

的FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/btnButton"
            android:text="Hello"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />
    </FrameLayout>
</FrameLayout>
RelativeLayout的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/btnButton"
            android:text="Hello"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />
    </RelativeLayout>
</RelativeLayout>
以上两个代码只能像第一张图像一样工作.我想要的是第二张图片.
有人可以帮忙吗?
谢谢.
Che*_*mon 177
一个FrameLayout宗旨是覆盖在彼此之上的东西.这不是你想要的.
在您的RelativeLayout示例中,您将ListViews的高度和宽度设置MATCH_PARENT为使其占用与其父级相同的空间量,从而占用页面上的所有空间(并覆盖按钮).  
尝试类似的东西:
<LinearLayout 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical">
  <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1"/>
  <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0"/>
</LinearLayout>
这layout_weight决定了如何使用额外的空间.本Button不想舒展超越它需要的空间,所以它具有0的重量ListView要占用所有的额外空间,所以它具有权重为1.
你可以使用a来完成类似的事情RelativeLayout,但如果它只是这两个项目,那么我认为LinearLayout更简单.