Java 尝试在列表视图下放置按钮
因此,我正在创建一个列表视图,该视图根据用户输入进行缩放,我需要四个按钮,但我不知道如何使按钮与列表视图的底部对齐,并以2x2网格的方式。我已经尝试过相对布局,但似乎不起作用。谢谢我根据我认为您希望看到的内容创建了XML。 请检查以下屏幕截图: 以下是XML文件:Java 尝试在列表视图下放置按钮,java,android,Java,Android,因此,我正在创建一个列表视图,该视图根据用户输入进行缩放,我需要四个按钮,但我不知道如何使按钮与列表视图的底部对齐,并以2x2网格的方式。我已经尝试过相对布局,但似乎不起作用。谢谢我根据我认为您希望看到的内容创建了XML。 请检查以下屏幕截图: 以下是XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BUTTON3"/>
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BUTTON4"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_above="@id/linearLayout1">
<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>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/linearLayout2">
</ListView>
</RelativeLayout>
正如您所看到的,我使用RelativeLayout作为基本包装器,在RelativeLayout中,我有两个用于按钮2的线性布局,最后是列表视图。线性布局的目的只是增加按钮的重量,使其共享相等的水平空间。如果这不符合您的标准,请随意删除它们。要学习的主要内容是,相对布局允许您使用诸如alignParenBottom、layout_Upper、layout_Down等属性。这些属性允许您将元素放置在屏幕上的任何位置,并根据这些属性进行调整。
如果您有任何问题,请与我联系。无论ListView请求的空间有多大,按钮都应位于ListView下方,并且始终可见于活动底部。::另外,请使用您已经尝试过的布局编辑您的问题,以便可以将其用作问题的基础answer@Barns是的,我想把2x2的按钮放在列表的底部,不管它有多长。你可以使用RelativeLayout。首先添加按钮容器并将其固定到活动的底部。然后添加具有match_父属性但位于按钮容器上方的ListView。那就行了