假设我想列出按钮,以便将最后一个按钮固定在屏幕底部,我将如何处理。据我了解,LinearLayout 会给我按钮的“列表”,但它会固定在顶部。另一方面,RelativeLayout 将允许我锚定到底部,但每个元素都必须具有对下一个元素的引用,并且 XML 文件的顺序将是相反的(因此引用是有效的)。
我应该如何处理这个?
编辑:抱歉,这大概就是我要找的 -
假设我想列出按钮,以便将最后一个按钮固定在屏幕底部,我将如何处理。据我了解,LinearLayout 会给我按钮的“列表”,但它会固定在顶部。另一方面,RelativeLayout 将允许我锚定到底部,但每个元素都必须具有对下一个元素的引用,并且 XML 文件的顺序将是相反的(因此引用是有效的)。
我应该如何处理这个?
编辑:抱歉,这大概就是我要找的 -
您可以尝试添加一个权重为 1 的额外 LinearLayout 以占用所有剩余空间,并将按钮列表推到 Activity 底部:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button
android:id="@+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
示例 XML 用于由 LinearLayout 推送到 Activity 底部的单个按钮;根布局也是线性的。
我很难准确理解你的问题。但我假设你想要的是一个固定在屏幕底部的水平按钮列表?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- put your other views in here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="cancel" />
<Button
android:id="@+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="ok" />
</LinearLayout>
</LinearLayout>