我在框架布局中有两个按钮,希望它们在屏幕底部对齐,一个在另一个下方。
使用 android:layout_gravity="bottom"
使它们相互重叠。我使用 Relativelayout 没有问题,但 relativelayout 不支持 android:layout_gravity="bottom"
我的 XML 布局文件
<?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"
android:background="@drawable/bg"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scanit"
android:layout_gravity="bottom"
android:text="Button 1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/inf"
android:layout_gravity="bottom"
android:text="Button 2" />
</FrameLayout>
最佳答案
为此使用下面的布局代码,它可能对您有所帮助。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_above="@+id/mLlayoutBottomButtons" >
</RelativeLayout>
<LinearLayout
android:id="@+id/mLlayoutBottomButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2" />
</LinearLayout>
</RelativeLayout>
关于android - 将按钮对齐到屏幕底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11272106/