簡體   English   中英

NestedScrollView 不在 CoordinatorLayout 內滾動 - Android

[英]NestedScrollView not scrolling inside CoordinatorLayout - Android

以下布局中的嵌套滾動視圖不滾動。 如果我刪除協調器布局,滾動工作。 但是,我想保留協調器布局以將 fab 按鈕放在卡片視圖的底部。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
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="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_yellow_color">

    <androidx.cardview.widget.CardView
        android:id="@+id/content_card"
        style="@style/card_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.375">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="fill_vertical"
                android:fillViewport="true">

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

                    <TextView
                        android:id="@+id/tv_title"
                        style="@style/form_title"
                        android:text="@string/title" />

                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/name"
                        style="@style/form_input_layout"
                        android:layout_marginTop="@dimen/margin_40dp"
                        android:hint="@string/vendor_name">

                        <com.google.android.material.textfield.TextInputEditText
                            style="@style/form_input_field"
                            android:inputType="textPersonName"
                            android:maxLines="1" />
                    </com.google.android.material.textfield.TextInputLayout>

                   <!--a lot of other input fields here-->

                </LinearLayout>
            </androidx.core.widget.NestedScrollView>
    </androidx.cardview.widget.CardView>
</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab_next"
    style="@style/fab_next"
    app:layout_anchor="@id/content_card" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

請分享您對此的看法。 我被困了一段時間。

只需將 AppBarLayout 放在 NestedScrollView 內...就像這樣

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent">


        <androidx.core.widget.NestedScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/bg_yellow_color">

            <androidx.cardview.widget.CardView
                android:id="@+id/content_card"
                style="@style/card_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.375">


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

                    <TextView
                        android:id="@+id/tv_title"
                        style="@style/form_title"
                        android:text="@string/title" />

                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/name"
                        style="@style/form_input_layout"
                        android:layout_marginTop="@dimen/margin_40dp"
                        android:hint="@string/vendor_name">

                        <com.google.android.material.textfield.TextInputEditText
                            style="@style/form_input_field"
                            android:inputType="textPersonName"
                            android:maxLines="1" />
                    </com.google.android.material.textfield.TextInputLayout>

                    <!--a lot of other input fields here-->

                </LinearLayout>

            </androidx.cardview.widget.CardView>
        </com.google.android.material.appbar.AppBarLayout>
    </androidx.core.widget.NestedScrollView>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_next"
        style="@style/fab_next"
        app:layout_anchor="@id/content_card" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM