如何在UI底部的固定位置设置按钮?

时间:2011-06-29 10:40:56

标签: android

我希望按钮在UI的页脚中始终显示在固定位置? (总是,如果它上面有组件,那么

5 个答案:

答案 0 :(得分:26)

请在主布局下选择一个相对布局。将其高度和宽度设置为填充父级,并将其重力设置为底部,并将任何textview或任何按钮放入其中。

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

    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:gravity="bottom">

        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Bottom Gravity" />

    </RelativeLayout>

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Without Gravity" />

    </LinearLayout>

</FrameLayout>

enter image description here

答案 1 :(得分:6)

这取决于您使用的布局。

在RelativeLayout上有

android:layout_alignParentBottom="true"

在LinearLayout上,将其放在底部,并确保正确设置layout_weight元素。

另外,检查属性

android:layout_gravity

并注意到它与

不同
android:gravity

答案 2 :(得分:2)

设置android:layout_gravity="bottom"。希望这会有所帮助。

答案 3 :(得分:1)

如果有任何一个人有两个按钮,你可以让它为我打电话

Math.round(Math.random() * (array.length - 1))

答案 4 :(得分:0)

android:layout_alignParentBottom="true"

在您的相对布局中。