当Edittext的内容增长时,父滚动视图也会滚动

时间:2017-01-03 07:49:57

标签: android android-edittext scrollview

我有一个带垂直滚动的edittext。这保存在父卷轴视图中。

当edittext的内容溢出以滚动时,父卷轴也会滚动。

由于滚动,我的edittext上升,用户看不到它。

当子edittext内容足够大时,我不希望父级滚动。

如何实现这一目标?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout_root"
    android:layout_width="match_parent"
    android:isScrollContainer="false"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusableInTouchMode="true">

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dimen_15"
                android:layout_marginRight="@dimen/dimen_22"
                android:layout_marginTop="@dimen/dimen_30">

                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/new_dummy_title_txt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:textColor="@color/dicussion_title_name_color"
                    android:textSize="@dimen/dimen_sp_20"
                    app:fontName="OpenSans-Regular.ttf" />

                <ImageView
                    android:id="@+id/new_dummy_close_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:src="@drawable/dummy_close_img" />

            </RelativeLayout>

            <com.dummy.widgets.TextViewCustom
                android:id="@+id/dummy_title_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_19"
                android:textColor="@color/dummy_sub_heading_title"
                android:textSize="@dimen/dimen_sp_16"
                app:fontName="OpenSans-Regular.ttf" />

            <com.dummy.widgets.TextViewCustom
             android:id="@+id/dummy_title_reminder_txt"
              android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:layout_marginRight="@dimen/dimen_17"
                android:textColor="@color/create_dummy_txt_reminder"
                android:textSize="@dimen/dimen_sp_14" />


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen_42"
                android:layout_marginLeft="@dimen/dimen_16"
                android:layout_marginRight="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_4"
                android:background="@drawable/dummy_editext_bg">

                <View
                    android:id="@+id/dicussion_title_highlight_view"
                    android:layout_width="@dimen/dimen_5"
                    android:layout_height="match_parent"
                    android:background="@color/create_dummy_view_highlight"
                    android:visibility="gone" />

                <com.dummy.widgets.EditTextCustom
                    android:id="@+id/dicussion_title_etxt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="@dimen/dimen_13"
                    android:layout_marginRight="@dimen/dimen_16"
                    android:background="@null"
                    android:maxLength="28"
                    android:singleLine="true"
                    android:textColor="@color/dummy_sub_heading_title"
                    android:textColorHint="@color/create_dummy_hint_color"
                    android:textSize="@dimen/dimen_sp_14"
                    app:fontName="OpenSans-Regular.ttf" />

            </RelativeLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_29"
                android:orientation="horizontal">

                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/dicussion_statement_txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/dummy_sub_heading_title"
                    app:fontName="OpenSans-Regular.ttf" />

                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/dicussion_statement_optional_txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_5"
                    android:textColor="@color/dummys_toc_content_color_regular"
                    app:fontName="OpenSans-Regular.ttf" />

            </LinearLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen_103"
                android:layout_marginLeft="@dimen/dimen_16"
                android:layout_marginRight="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_15"
                android:background="@drawable/dummy_editext_bg">


                <View
                    android:id="@+id/dicussion_statement_highlight_view"
                    android:layout_width="@dimen/dimen_5"
                    android:layout_height="match_parent"
                    android:background="@color/create_dummy_view_highlight"
                    android:visibility="gone" />


                <com.dummy.widgets.EditTextCustom
                    android:id="@+id/dicussion_statement_etxt"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dimen_103"
                    android:layout_marginLeft="@dimen/dimen_13"
                    android:layout_marginTop="@dimen/dimen_9"
                    android:background="@null"
                    android:gravity="start"
                    android:lines="5"
                    android:inputType="textMultiLine"
                    android:overScrollMode="always"
                    android:scrollbarStyle="insideInset"
                    android:scrollbars="vertical"
                    android:singleLine="false"
                    android:textColor="@color/dummy_sub_heading_title"
                    android:textColorHint="@color/create_dummy_hint_color"
                    android:textSize="@dimen/dimen_sp_14"
                    app:fontName="OpenSans-Regular.ttf" />

            </RelativeLayout>

            <com.dummy.widgets.TextViewCustom
                android:id="@+id/create_dummy_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_23"
                android:textColor="@color/dummy_sub_heading_title" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen_248"
                android:layout_marginLeft="@dimen/dimen_13"
                android:layout_marginRight="@dimen/dimen_16"
                android:layout_marginTop="@dimen/dimen_15"
                android:background="@drawable/dummy_editext_bg">

                <View
                    android:id="@+id/create_dummy_highlight_view"
                    android:layout_width="@dimen/dimen_5"
                    android:layout_height="match_parent"
                    android:background="@color/create_dummy_view_highlight"
                    android:visibility="gone" />

                <com.dummy.widgets.EditTextCustom
                    android:id="@+id/create_dummy_etxt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/preview_post_txt"
                    android:layout_marginLeft="@dimen/dimen_11"
                    android:layout_marginTop="@dimen/dimen_9"
                    android:background="@null"
                    android:gravity="start"
                    android:scrollbars="vertical"
                    android:textColor="@color/dummy_sub_heading_title"
                    android:textColorHint="@color/create_dummy_hint_color"
                    android:textSize="@dimen/dimen_sp_14"
                    android:visibility="visible"
                    app:fontName="OpenSans-Regular.ttf" />


                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/preview_post_txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginBottom="@dimen/dimen_17"
                    android:layout_marginRight="@dimen/dimen_16"
                    android:drawablePadding="@dimen/dimen_9"
                    android:drawableRight="@drawable/dummy_preview_light_img"
                    android:gravity="center"
                    android:textColor="@color/preview_post_text_normal" />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dimen_17">

                <ImageView
                    android:id="@+id/add_members_description_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_17"
                    android:src="@drawable/dummy_add_people_img" />

                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/add_members_description_txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginLeft="@dimen/dimen_12"
                    android:layout_marginRight="@dimen/dimen_25"
                    android:layout_toRightOf="@+id/add_members_description_img"
                    android:textColor="@color/preview_post_text_highlighted"
                    app:fontName="OpenSans-Regular.ttf" />
            </RelativeLayout>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="@dimen/dimen_49"
                android:layout_marginTop="@dimen/dimen_34"
                android:orientation="horizontal">

                <com.dummy.widgets.TextViewCustom
                    android:id="@+id/create_dummy_cancel_btn"
                    android:layout_width="@dimen/dimen_98"
                    android:layout_height="@dimen/dimen_35"
                    android:layout_marginLeft="@dimen/dimen_21"
                    android:layout_toLeftOf="@+id/create_dummy_btn"
                    android:gravity="center"
                    android:textColor="@color/dummy_sub_heading_title"
                    android:textSize="@dimen/dimen_sp_14"
                    app:fontName="OpenSans-Semibold.ttf" />

                <Button
                    android:id="@+id/create_dummy_btn"
                    android:layout_width="@dimen/dimen_181"
                    android:layout_height="@dimen/dimen_35"
                    android:layout_alignParentRight="true"
                    android:layout_marginLeft="@dimen/dimen_38"
                    android:layout_marginRight="@dimen/dimen_21"
                    android:background="@color/create_dummy_disabled_btn"
                    android:textColor="@color/create_dummy_btn_normal_text"
                    android:textSize="@dimen/dimen_sp_14" />
            </RelativeLayout>

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

0 个答案:

没有答案