1

我正在尝试将 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>

请协助。

谢谢

4

2 回答 2

3

你的身份证android:layout_below="@+id/username_input_layout"上似乎有:EditTextandroid: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

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

于 2015-08-27T08:32:19.433 回答
1

如果通过堆叠您的意思是TextInputLayouts相互叠加,那么这可能是因为您使用的是RelativeLayout. 如果您希望这些显示在另一个下方,则可以切换到LinearLayout设置android:orientation为 的vertical,或使用该android:layout_below属性来指定视图之间的正确关系。

于 2015-08-27T08:33:34.823 回答