安卓:你该如何调整的底部和列表视图上方的按钮? [英] Android: How can you align a button at the bottom and listview above?

查看:201
本文介绍了安卓:你该如何调整的底部和列表视图上方的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个按钮,在列表视图的底部。

I want to have a button at the bottom of the listview.

如果我用RelativeLayout的/的FrameLayout,它对齐但ListView控件下降到非常钮。

If I use relativeLayout/FrameLayout, it aligns but listView goes down to very botton.

(背部底部的按钮)

的FrameLayout:

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的:

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>

以上两种codeS只工作像第一张图像。我要的是第二个图像。

Above two codes only work like the first image. What I want is second image.

有人能帮忙吗?

感谢你。

推荐答案

A 的FrameLayout 的目的是为了覆盖东西彼此顶部。这是不是你想要的。

A FrameLayouts purpose is to overlay things on top of each other. This is not what you want.

在你的 RelativeLayout的例如将的ListView 的身高和宽度 MATCH_PARENT 这将使其占用的空间是其父母相同的量,从而占用了所有的空间页面上(并覆盖按钮)。

In your RelativeLayout example you set the ListViews height and width to MATCH_PARENT this is going to make it take up the same amount of space as its parent, and thus take up all of the space on the page (and covers the button).

试着这么做:

<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 决定了额外的空间是如何被使用。该按钮不想舒展超越它需要的空间,所以它有一个0重量的ListView 希望为占用所有的额外空间,因此它具有1的权重。

The layout_weight dictates how the extra space is to be used. The Button does not want to stretch beyond the space it requires, so it has a weight of 0. The ListView wants to take up all of the extra space, so it has a weight of 1.

您可以完成使用类似的东西 RelativeLayout的,但如果仅仅是这两个项目,然后我觉得的LinearLayout 更简单

You could accomplish something similar using a RelativeLayout, but if it is just these two items then I think a LinearLayout is simpler.

这篇关于安卓:你该如何调整的底部和列表视图上方的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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