添加页脚的最佳方法是什么,无论屏幕分辨率如何,都会在底部?

时间:2012-12-28 06:18:09

标签: android android-layout footer

我正在开发一个应用程序,无论屏幕分辨率如何,我都需要在底部放置两个按钮。

最好实现这个目标?

3 个答案:

答案 0 :(得分:1)

在新布局中设置这些按钮(相对/线性 - 与布局视图相对应)并提供android:layout_alignParentBottom="true"

答案 1 :(得分:1)

使用底部的RelativeLayout withLinearLayout。只需一种方法,并使用layout_weight设置相同大小的按钮。

<强>更新

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

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

    <Button
        android:id="@+id/idBtn2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button 2" />
</LinearLayout>

答案 2 :(得分:0)

尝试这种方式使用页脚常用:

首先创建一个footer.xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >   
        <LinearLayout
            android:id="@id/idFooterMenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
            <Button
                android:id="@+id/footerBtn1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Button1" />   
            <Button
                android:id="@+id/footerBtn2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Button2" />
        </LinearLayout>
</RelativeLayout>

然后,您可以在任何其他屏幕中使用此footer.xml文件,而无需重复代码

<include layout="@layout/footer" />

感谢。

相关问题