如何在 LinearLayout 下方显示按钮



我正在使用LinearLayout,因为它是我可以使用layout_weight的唯一方法,而且我对在RelativeLayout中均匀对齐文本视图不够熟悉。(我是安卓新手)。如何获得线性布局下方的按钮?请注意,我已经在stackoverflow上搜索了这个问题,但我没有找到任何对我有意义或有效的内容。

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/llRegister2"
            android:layout_below="@+id/tvRegister2ShopTiming"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="30dp"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1">
                <EditText
                    android:id="@+id/etRegister2StartTime"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Start Time"
                    android:textColorHint="#311D3F"
                    android:textColor="#311D3F"
                    android:layout_marginRight="10dp"
                    android:focusable="false"
                    android:editable="false"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                >
                <EditText
                    android:id="@+id/etRegister2EndTime"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="End Time"
                    android:layout_marginLeft="10dp"
                    android:textColorHint="#311D3F"
                    android:textColor="#311D3F"
                    android:focusable="false"
                    android:editable="false"/>
            </LinearLayout>
        </LinearLayout>
        <Button
            android:id="@+id/btnRegister2Next"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="30dp"
            android:background="@drawable/button"
            android:text="NEXT"
            android:textSize="18sp"
            android:textColor="@android:color/white"
            android:layout_alignParentBottom="true"
            />

您可以简化布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/llRegister2"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="5dp"
    android:layout_marginRight="30dp"
    android:orientation="horizontal">

        <EditText
            android:id="@+id/etRegister2StartTime"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:hint="Start Time"
            android:textColorHint="#311D3F"
            android:textColor="#311D3F"
            android:layout_marginRight="10dp"
            android:focusable="false"
            android:editable="false"/>

        <EditText
            android:id="@+id/etRegister2EndTime"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:hint="End Time"
            android:layout_marginLeft="10dp"
            android:textColorHint="#311D3F"
            android:textColor="#311D3F"
            android:focusable="false"
            android:editable="false"/>
</LinearLayout>
<Button
    android:id="@+id/btnRegister2Next"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:background="@drawable/button"
    android:text="NEXT"
    android:layout_below="@+id/llRegister2"
    android:textSize="18sp"
    android:textColor="@android:color/white"
    android:layout_alignParentBottom="true"
    />

RelativeLayout 具有在 XML 中任何位置对齐视图的属性。您的根视图是相对布局,因此请将此行添加到您的按钮:

android:layout_below="@+id/llRegister2" //i'd of your LinearLayout.
android:layout_alignParentBottom="true"

快乐编码!!

试试这段代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/llRegister2"
        android:orientation="horizontal"
        android:weightSum="2"
        android:padding="10dp"
        android:layout_above="@+id/btnRegister2Next"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="27dp">
            <EditText
                android:id="@+id/etRegister2StartTime"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Start Time"
                android:textColorHint="#311D3F"
                android:textColor="#311D3F"
                android:layout_marginRight="10dp"
                android:layout_weight="1"/>

            <EditText
                android:id="@+id/etRegister2EndTime"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="End Time"
                android:layout_marginLeft="10dp"
                android:textColorHint="#311D3F"
                android:textColor="#311D3F"
                android:layout_weight="1"/>
    </LinearLayout>
    <Button
        android:id="@+id/btnRegister2Next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NEXT"
        android:textSize="18sp"
        android:textColor="@android:color/white"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="223dp" />
</RelativeLayout>

最新更新