顶部的ListView的布局和底部的按钮的布局? [英] Layout for ListView at top and Buttons in Bottom?

查看:56
本文介绍了顶部的ListView的布局和底部的按钮的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示布局,顶部为 ListView ,底部为多个 Buttons (如图所示)

How to display the layout with a ListView at top and mutliple Buttons at the bottom (as in pic)

下面是我尝试的代码(问题是按钮与列表重叠,这在按钮后面有点可见&尽管我使用了权重总和,但3个按钮的大小并不相等):

Below is the code that I tried (Problem is the buttons are overlapping the list which is somewhat visible behind the buttons & the 3 buttons are not equal is size though I used the weight sum):

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="3" >

        <Button
            android:id="@+id/bDone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Done" />

        <Button
            android:id="@+id/bCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel" />

        <Button
            android:id="@+id/bSelAll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Select All" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>

</RelativeLayout>

推荐答案

我所做的基本上是2种线性布局,1种用于列表,1种用于按钮.同样将权重设置为1并将宽度设置为0将使它们的大小相等这段代码对我有用:

What I did is basically do a 2 linear layouts, 1 for the list and 1 for the button. Also setting the weight = 1 and the width = 0 will make them equal size This code worked for me:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="5dip"  
    android:layout_marginBottom="5dip"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_above="@+id/footerlayout"
    android:id="@+id/listviewlayout">
    <ListView
        android:id="@+id/list"               
        android:layout_width="fill_parent"               
        android:layout_height="wrap_content"  
        android:layout_weight="1">
    </ListView> 
 </LinearLayout>
 <LinearLayout android:id="@+id/footerlayout"
        android:layout_marginTop="3dip"
        android:layout_height="45dip"
        android:orientation="horizontal" 
        android:layout_width="fill_parent" 
        android:gravity="center"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/bDone" 
            android:text="Done" 
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1">
        </Button>   
        <Button
            android:id="@+id/bCancel" 
            android:text="Cancel"
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1"   
            >
        </Button>   
        <Button
            android:id="@+id/bSelAll" 
            android:text="Select All"
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1"
            >
        </Button>   
    </LinearLayout>
</RelativeLayout>

这篇关于顶部的ListView的布局和底部的按钮的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆