gpt4 book ai didi

java - 尝试将按钮放置在 ListView 下方

转载 作者:行者123 更新时间:2023-12-02 10:45:54 29 4
gpt4 key购买 nike

因此,我正在创建一个根据用户输入增大和缩小的 ListView ,我需要四个按钮,但我不知道如何让按钮与 ListView 的底部对齐并位于2x2 网格时尚。我已经尝试过相对布局,但似乎不起作用。谢谢

最佳答案

我已经根据我相信您想要看到的内容创建了 XML。请检查以下屏幕截图:screen shot here

以下是 XML 文件:

<?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个用于按钮的线性布局(每个2个),最后是 ListView 。 LinearLayout 的目的只是增加按钮的权重,以便它们共享相同数量的水平空间。如果这不符合您的标准,请随时删除它们。 主要要学习的事情是,相对布局允许您使用alignParenBottom、layout_above、layout_below 等属性。这些属性允许您将元素放置在屏幕上的任何位置,并根据这些属性进行调整。

如果您有任何疑问,请告诉我。

关于java - 尝试将按钮放置在 ListView 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52581766/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com