滚动视图中的TextInputLayout

3
我将使用ScrollView内的TextInputLayout。当我打开应用程序时,视图显示正常,但是当我开始滚动时,原始视图仍然显示在其下方。我附上了快照,请告诉我问题所在。
打开应用程序时,它看起来像这样:

when i come to the app

当我开始滚动时,它看起来像这样:

when i start scrolling

这是我的代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "@android:color/transparent"

    >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/attch_photo_ll"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_margin="5dp"
        android:background="#CBCFD3"
        >
        <Button
            android:id="@+id/attach_photo_btn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:textStyle="bold"
            android:textSize="@dimen/_13sdp"
            android:inputType="textNoSuggestions"
            android:paddingLeft="10dp"
            android:textColor="@android:color/white"
            android:text="Attach Photo"
            />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/photo_ll"
        android:visibility="gone"
        android:layout_width="@dimen/image_width"
        android:layout_height="@dimen/image_height"
        android:layout_margin="5dp"
        android:layout_gravity="center"
        android:gravity="center">
        <ImageView
            android:id="@+id/photo_img"
            android:adjustViewBounds="true"
            android:layout_width="@dimen/image_width"
            android:layout_height="@dimen/image_height"
            android:scaleType="fitXY"/>
    </LinearLayout>

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

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="First Name" />

    </android.support.design.widget.TextInputLayout>


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

        <EditText
            android:id="@+id/lastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Last Name" />

    </android.support.design.widget.TextInputLayout>



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

        <EditText
            android:id="@+id/mobile_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Mobile 1" />

    </android.support.design.widget.TextInputLayout>



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

        <EditText
            android:id="@+id/mobile_two"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Mobile 2 (Optional)" />

    </android.support.design.widget.TextInputLayout>



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

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

    </android.support.design.widget.TextInputLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="@dimen/_8sdp"
        android:orientation="horizontal"
        android:weightSum="3">

        <android.support.design.widget.TextInputLayout
            android:layout_weight="1"
            android:id="@+id/input_layout_aadhar_card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/aadhar_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Aadhar No." />

        </android.support.design.widget.TextInputLayout>


        <android.support.design.widget.TextInputLayout
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/aadhar_card1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/aadhar_card2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="@dimen/_8sdp"
        android:layout_marginBottom="@dimen/_8sdp"
        android:orientation="horizontal"
        android:weightSum="3">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/pancard"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Pan Card No."/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard1"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/pancard1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard2"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/pancard2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>
</LinearLayout>
</ScrollView>

你可以将这个布局用作对话框吗? - Hiren Vaghela
从LinearLayout和ScrollView中删除背景 @AmitRanjan - Kiran Benny Joseph
移除 android:background = "@android:color/transparent"。 - Kiran Benny Joseph
2个回答

1

尝试这个。
在您的布局中,从EditText中删除提示并将提示添加到TextInputLayout中。
例如:

   <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_username"
        android:layout_width="match_parent"
        android:hint="First Name"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>

当我开始滚动时,它不起作用,然后视图仍然在后台,并且在其上方的相同视图正在滚动。 - Amit Ranjan

-2
请将以下布局文件复制并粘贴到您现有的代码中,这样您的问题就可以得到解决:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/attch_photo_ll"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_margin="5dp"
        android:background="#CBCFD3">

        <Button
            android:id="@+id/attach_photo_btn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:inputType="textNoSuggestions"
            android:paddingLeft="10dp"
            android:text="Attach Photo"
            android:textColor="@android:color/white"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/photo_ll"
        android:layout_width="@dimen/image_width"
        android:layout_height="@dimen/image_height"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:gravity="center"
        android:visibility="gone">

        <ImageView
            android:id="@+id/photo_img"
            android:layout_width="@dimen/image_width"
            android:layout_height="@dimen/image_height"
            android:adjustViewBounds="true"

            android:scaleType="fitXY" />
    </LinearLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="First Name">

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_lastName"
        android:layout_width="match_parent"

        android:layout_height="wrap_content"
        android:hint="Last Name">

        <EditText
            android:id="@+id/lastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_mobile_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Mobile 1">

        <EditText
            android:id="@+id/mobile_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_mobile_two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Mobile 2 (Optional)">

        <EditText
            android:id="@+id/mobile_two"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email">

        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:orientation="horizontal"
        android:weightSum="3">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_aadhar_card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Aadhar No.">

            <EditText
                android:id="@+id/aadhar_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>


        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <EditText
                android:id="@+id/aadhar_card1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <EditText
                android:id="@+id/aadhar_card2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:orientation="horizontal"
        android:weightSum="3">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Pan Card No.">

            <EditText
                android:id="@+id/pancard"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <EditText
                android:id="@+id/pancard1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_pancard2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <EditText
                android:id="@+id/pancard2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>
</LinearLayout>


无法正常工作,请仔细查看第二张截图,当我开始滚动时,相同的视图在后台,并且从顶部滚动相同的视图,为什么会渲染? - Amit Ranjan
我在Fragment中有这个视图,并将此视图添加到Activity中。 - Amit Ranjan
不要只是粘贴代码,解释为什么它能工作,否则这会让提问者和其他人难以理解你的解决方案。 - FabioR

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接