Android:TextInputLayout 相互堆叠

Android: TextInputLayout stacking on eachother

我正在尝试对我的布局实施 TextInputLayout。我有 3 个 EditText。我将每个包装在一个单独的 TextInputLayout 中。

它们没有分开,而是堆叠在一起。


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_colour">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp"
    android:paddingBottom="16dp">

    <RelativeLayout
        android:id="@+id/sign_in_form_relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:gravity="center"
        android:padding="8dp">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/username_input_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/sign_in_username"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_alignParentTop="true"
                android:background="@drawable/apptheme_edit_text_holo_light"
                android:drawableLeft="@drawable/ic_action_unread"
                android:drawablePadding="8dp"
                android:drawableStart="@drawable/ic_action_unread"
                android:hint="@string/sign_in_username_field"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress|textNoSuggestions"
                android:textAppearance="?android:textAppearanceMedium" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/password_input_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/sign_in_password"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_below="@+id/username_input_layout"
                android:background="@drawable/apptheme_edit_text_holo_light"
                android:drawableLeft="@drawable/ic_action_secure_dark"
                android:drawablePadding="8dp"
                android:drawableStart="@drawable/ic_action_secure_dark"
                android:hint="@string/reg_password"
                android:imeOptions="actionNext"
                android:inputType="textPassword"
                android:textAppearance="?android:textAppearanceMedium" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/server_api_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/sign_in_api_url"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:layout_below="@+id/password_input_layout"
                android:background="@drawable/apptheme_edit_text_holo_light"
                android:drawableLeft="@drawable/ic_action_private_server"
                android:drawablePadding="8dp"
                android:drawableStart="@drawable/ic_action_private_server"
                android:hint="@string/sign_in_server_field"
                android:imeOptions="actionDone"
                android:inputType="textUri"
                android:textAppearance="?android:textAppearanceMedium" />
        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/sign_in_button"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_below="@id/server_api_layout"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:background="@drawable/selector_normal_to_bright"
            android:padding="8dp"
            android:text="@string/reg_sign_in"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white" />

        <TextView
            android:id="@+id/sign_in_forgot_pwd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/sign_in_button"
            android:layout_margin="12dp"
            android:layout_marginBottom="24dp"
            android:clickable="true"
            android:gravity="end"
            android:paddingBottom="16dp"
            android:text="@string/reg_forgot_password"
            android:textAlignment="textEnd"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@color/flavor_hyperlink_text_colour"
            android:textStyle="bold" />
    </RelativeLayout>

</ScrollView>

请协助。

谢谢

您的 EditText 上似乎有 android:layout_below="@+id/username_input_layout",ID:android:id="@+id/sign_in_password"

相反,您应该将它放在您的 TextInputLayout 上,ID 为:android:id="@+id/password_input_layout",如下所示:

    <android.support.design.widget.TextInputLayout
        android:id="@+id/username_input_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/sign_in_username"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_alignParentTop="true"
            android:background="@drawable/apptheme_edit_text_holo_light"
            android:drawableLeft="@drawable/ic_action_unread"
            android:drawablePadding="8dp"
            android:drawableStart="@drawable/ic_action_unread"
            android:hint="@string/sign_in_username_field"
            android:imeOptions="actionNext"
            android:inputType="textEmailAddress|textNoSuggestions"
            android:textAppearance="?android:textAppearanceMedium" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/password_input_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android.layou_below="@+id/username_input_layout">

        <EditText
            android:id="@+id/sign_in_password"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/apptheme_edit_text_holo_light"
            android:drawableLeft="@drawable/ic_action_secure_dark"
            android:drawablePadding="8dp"
            android:drawableStart="@drawable/ic_action_secure_dark"
            android:hint="@string/reg_password"
            android:imeOptions="actionNext"
            android:inputType="textPassword"
            android:textAppearance="?android:textAppearanceMedium" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/server_api_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android.layou_below="@+id/password_input_layout">

        <EditText
            android:id="@+id/sign_in_api_url"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/apptheme_edit_text_holo_light"
            android:drawableLeft="@drawable/ic_action_private_server"
            android:drawablePadding="8dp"
            android:drawableStart="@drawable/ic_action_private_server"
            android:hint="@string/sign_in_server_field"
            android:imeOptions="actionDone"
            android:inputType="textUri"
            android:textAppearance="?android:textAppearanceMedium" />
    </android.support.design.widget.TextInputLayout>

这是使用方法layout_below

container1
    editText
container below container1
    editText

您尝试这样做:

container
    editText
container
    editText below container1

试试这个,请报告你的进度

如果您所说的堆叠是指 TextInputLayouts 相互重叠,那么发生这种情况的原因可能是您使用的是 RelativeLayout。如果您希望它们一个接一个地出现,请切换到 LinearLayout 并将 android:orientation 设置为 vertical,或者使用 android:layout_below 属性指定正确的关系观看次数。