gpt4 book ai didi

android - 如何使用线性布局将按钮设置到屏幕底部

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:21 24 4
gpt4 key购买 nike

我刚开始使用 Android 并具有以下代码。我想在屏幕底部显示三个按钮而不更改为相对布局。我尝试设置内部线性布局的 layout_weightgravity 但这会将按钮置于底部,在手机的三个菜单按钮后面。如何在菜单按钮上方显示它们?任何帮助将不胜感激。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:id="@+id/search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/search_box" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="80dp"
android:text="@string/welcome"
android:textSize="24sp" />

<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="horizontal">

<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/buttonB1" />

<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/buttonB2" />

<Button
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/buttonB3" />
</LinearLayout>
</LinearLayout>

左图显示了我想移至底部的按钮。右图显示了我这样做的尝试,但按钮最终部分位于系统菜单按钮的后面。

Buttons I want to move to the bottom Buttons behind the menu buttons of phone

最佳答案

尝试在每个按钮的底部添加边距。将此添加到每个按钮布局:android:layout_marginBottom="20dp"

如果这不起作用,请为线性布局本身添加一个底部边距。

关于android - 如何使用线性布局将按钮设置到屏幕底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37286131/

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