RelativeLayoutwith ScrollView和Button未在屏幕底部设置

时间:2017-06-25 14:47:05

标签: android scrollview android-relativelayout

我希望我的编辑按钮始终显示在屏幕底部。以下是我的代码。

<?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:padding="@dimen/dimen_16dp">
    <Button
        android:id="@+id/button_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:background="@color/colorPrimaryDark"
        android:text="@string/edit"
        android:textSize="20sp" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:layout_above="@+id/button_edit">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.design.widget.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/til_name_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="16dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_name_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/name"
                    android:inputType="textCapWords"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/til_dob_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_name_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:focusable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_dob_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:focusable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/date_of_birth"
                    android:inputType="date"
                    android:maxLength="10"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/til_gender"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_dob_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:focusable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_gender_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:focusable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/gender"
                    android:inputType="date"
                    android:maxLength="10"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_address_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_gender"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_address_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:gravity="clip_vertical"
                    android:hint="@string/house_no_sector_street_phase_floor_etc"
                    android:inputType="textCapSentences"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_pin_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_address_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_pin_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/pin_code"
                    android:inputType="number"
                    android:maxLength="6"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_state_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/til_pin_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_state_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/state"
                    android:inputType="textCapWords"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_contact_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_state_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_contact_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/mobile_no"
                    android:inputType="number"
                    android:maxLength="10"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_email_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_contact_view"
                android:layout_marginBottom="8dp"
                android:background="@drawable/register_layout_background"
                android:clickable="false"
                android:paddingBottom="16dp"
                android:paddingTop="16dp">

                <EditText
                    android:id="@+id/et_email_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:background="@color/transparent_color"
                    android:clickable="false"
                    android:focusable="false"
                    android:gravity="center_vertical"
                    android:hint="@string/e_mail"
                    android:inputType="textEmailAddress"
                    android:paddingTop="4dp" />
            </android.support.design.widget.TextInputLayout>
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

问题:问题是按钮没有显示在底部而是显示在屏幕顶部,而ScrollView根本看不到。如果我将外部RelativeLayout的android:layout_height =“match_parent”中的match_parent更改为某个值(如500dp),那么它可以正常工作,但只要我将其更改为match_parent,按钮就会显示在顶部。 任何人都可以帮我找到需要纠正的地方吗?感谢

1 个答案:

答案 0 :(得分:0)

我把FrameLayout放在scrollView中。并且在片段的布局中我试图再次使用scrollView,因此,我正面临着这个问题。我通过删除framelayout的滚动视图来解决它