ScrollView не работает в Coordinator и Relative layout - PullRequest
0 голосов
/ 15 декабря 2018

Следующий код отображает только 3 из 4 Editext в пределах ScrollView.Проблема в последнем Editext, который перекрывает Button

Почему ScrollView не работает должным образом?

Или Как избежать этого перекрытия?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.CoordinatorLayout
    android:id="@+id/cl"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/bt_next">

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


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_alignParentTop="true">

        <TextView
            android:id="@+id/tv_activity_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#fff"
            android:textSize="24sp"
            android:text="@string/app_name"/>

        </android.support.v7.widget.Toolbar>

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


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/mysv">


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

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


            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 2"/>

            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 3"/>

            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 4"/>

        </LinearLayout>

    </ScrollView>

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

<Button
    android:id="@+id/bt_next"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Next"/>

Так выглядит конец свитка.

enter image description here

Ответы [ 2 ]

0 голосов
/ 16 декабря 2018

Я решил использовать Nestedlayout и LinearLayout внутри.Ключ, имейте в виду, CoordinatorLayout работает как FrameLayout.

Единственная проблема, которую я обнаружил, заключается в том, что панель инструментов не скрывается при прокрутке.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bt_next"
        android:layout_alignParentTop="true">

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



        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/mysv">


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways">

            <TextView
                android:id="@+id/tv_activity_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#fff"
                android:textSize="24sp"
                android:text="@string/app_name"/>

            </android.support.v7.widget.Toolbar>

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


        <android.support.v4.widget.NestedScrollView
            android:id="@+id/mysv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


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

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


                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 2"/>

                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 3"/>

                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 4"/>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>
        </LinearLayout>

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

    <Button
        android:id="@+id/bt_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Next"/>


</RelativeLayout>
0 голосов
/ 15 декабря 2018

Ваша проблема не в ScrollView, ваша проблема в том, что у вас Button всплывает отдельно от CoordinatorLayout.Если вы пытаетесь получить содержимое над кнопкой, вы можете попробовать добавить alignToTopOf="@id/bt_next (я забыл точное имя атрибута, но вы поняли идею).Тогда Координатор должен сесть поверх кнопки.

Если это не то, что вы пытаетесь сделать, опубликуйте скриншот того, к чему вы пытаетесь добраться, и скриншот того, что сейчас сломалось.

...