首页 > 解决方案 > 如何在android studio中将居中按钮放在2个线性布局下方

问题描述

我的目标是有 2 列带有一个编辑文本和几个按钮,但我需要屏幕底部的一个按钮来确认这些值。我无法将其置于屏幕底部并使其居中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">
    <EditText
        android:id="@+id/etWe"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned"
        android:hint="@string/We"/>
    

</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical">
    <EditText
        android:id="@+id/etThey"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned"
        android:hint="@string/They"/>
</LinearLayout>

标签: androidandroid-layout

解决方案


XML布局将帮助您

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">
        <EditText
            android:id="@+id/etWe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberSigned"
            android:hint="@string/We"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">
        <EditText
            android:id="@+id/etThey"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="numberSigned"
            android:hint="@string/They"/>
    </LinearLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="center|bottom"
    android:orientation="vertical" >
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"/>
</LinearLayout>

在我看来使用RelativeLayout

android:layout_alignParentBottom="true"

推荐阅读