RelativeLayout中的ScrollView:底部布局阻止了ScrollView中的EditText

时间:2016-06-11 10:09:04

标签: android android-layout

这是我的XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent">


    <ScrollView
        android:layout_width="match_parent"
        android:isScrollContainer="false"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:background="#FFF"
            android:elevation="2dp"
            android:paddingBottom="32dp">

            <View
                android:id="@+id/view7"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_centerInParent="true" />

            <android.support.design.widget.TextInputLayout android:textColorHint="@color/textColorAbu"
                android:id="@+id/til_event_create_sport_date"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_below="@+id/s_sport"
                android:layout_alignLeft="@+id/til_event_create_sport_starttime"
                android:layout_alignStart="@+id/til_event_create_sport_starttime">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:hint="Date"
                    android:imeActionId="@+id/et_search"
                    android:imeActionLabel="@string/register.first_name"
                    android:imeOptions="actionUnspecified"
                    android:inputType="date"
                    android:singleLine="true"
                    android:id="@+id/et_sport_date" />

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

            <android.support.design.widget.TextInputLayout android:textColorHint="@color/textColorAbu"
                android:id="@+id/til_event_create_sport_starttime"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignEnd="@+id/view7"
                android:layout_alignRight="@+id/view7"
                android:layout_below="@+id/til_event_create_sport_date"
                android:layout_marginBottom="4dp"
                android:layout_marginLeft="4dp"
                android:layout_marginTop="4dp"
                android:layout_weight="1">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:hint="Start Time"
                    android:imeActionId="@+id/et_search"
                    android:imeActionLabel="@string/register.first_name"
                    android:imeOptions="actionUnspecified"
                    android:singleLine="true"
                    android:id="@+id/et_"
                    android:inputType="time" />

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

            <android.support.design.widget.TextInputLayout android:textColorHint="@color/textColorAbu"
                android:id="@+id/til_event_create_sport_endtime"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/til_event_create_sport_starttime"
                android:layout_toEndOf="@+id/til_event_create_sport_starttime"
                android:layout_toRightOf="@+id/til_event_create_sport_starttime"
                android:layout_weight="1">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:hint="End Time"
                    android:imeActionId="@+id/et_search"
                    android:imeActionLabel="@string/register.first_name"
                    android:imeOptions="actionUnspecified"
                    android:inputType="time"
                    android:singleLine="true" />

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

            <android.support.design.widget.TextInputLayout android:textColorHint="@color/textColorAbu"
                android:id="@+id/til_event_create_sport_location"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_event_create_sport_starttime"
                android:layout_margin="4dp">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:hint="Location"
                    android:imeActionId="@+id/et_search"
                    android:imeActionLabel="@string/register.first_name"
                    android:imeOptions="actionUnspecified"
                    android:inputType="date"
                    android:singleLine="true"
                    android:id="@+id/et_location" />
            </android.support.design.widget.TextInputLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/til_event_create_sport_location"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:id="@+id/linearLayout4">

                <TextView
                    android:id="@+id/textView43"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/til_event_create_sport_location"
                    android:layout_alignStart="@+id/til_event_create_sport_location"
                    android:layout_below="@+id/til_event_create_sport_location"
                    android:layout_weight="1"
                    android:text="Event Type" />

                <Spinner
                    android:id="@+id/s_eventtype"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/textView43"
                    android:layout_toEndOf="@+id/til_event_create_sport_starttime"
                    android:layout_toRightOf="@+id/til_event_create_sport_starttime"
                    android:layout_weight="1"
                    android:entries="@array/eventtype_arrays"
                    android:spinnerMode="dropdown" />
            </LinearLayout>

            <android.support.design.widget.TextInputLayout android:textColorHint="@color/textColorAbu"
                android:id="@+id/til_event_create_sport_additionalinfo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/linearLayout4"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:hint="Additional Information"
                    android:imeActionId="@+id/et_search"
                    android:imeActionLabel="@string/register.first_name"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textMultiLine"
                    android:singleLine="false"
                    android:id="@+id/et_additional_info" />
            </android.support.design.widget.TextInputLayout>

            <Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/s_sport"
                android:spinnerMode="dialog"
                android:layout_below="@+id/textView10"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:entries="@array/sport_arrays" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sport Type"
                android:id="@+id/textView10"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textSize="13sp"
                android:textColor="@color/colorPrimary"
                android:layout_marginLeft="8dp" />

        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <LinearLayout
            android:id="@+id/ll_cancel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="8dp">

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:drawable/ic_menu_close_clear_cancel"
                android:src="@drawable/abc_ic_clear_mtrl_alpha" />

            <TextView
                android:id="@+id/textView8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="8dp"
                android:text="Cancel"
                android:textColor="@color/white"
                android:textSize="18sp" />

        </LinearLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:background="@color/white" />

        <LinearLayout
            android:id="@+id/ll_create"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="8dp">

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:drawable/ic_menu_close_clear_cancel"
                android:src="@drawable/abc_ic_clear_mtrl_alpha" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="8dp"
                android:text="Create"
                android:textColor="@color/white"
                android:textSize="18sp" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

(普通)布局如下所示: http://s33.postimg.org/60h0lwg67/Screenshot_2016_06_11_16_51_42_com_example_erdea.png

但是当我专注于EditText时,视图会阻止它: http://s33.postimg.org/61e3cubq7/Screenshot_2016_06_11_16_46_50_com_example_erdea.png

如何“删除”视图? (预期的结果是“按钮”没有显示在那里阻止编辑文本聚焦时)。谢谢!

2 个答案:

答案 0 :(得分:0)

尝试删除滚动视图的 android:layout_alignParentBottom =“true”并将其替换为 android:layout_alignParentTop =“true”

答案 1 :(得分:0)

您可以尝试在Android manifestxt XML中使用android:windowSoftInputMode="adjustPan" in your activity`元素。这样,当键盘出现时窗口不会调整大小。