首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NestedScrollView在CardView内不滚动

NestedScrollView在CardView内不滚动
EN

Stack Overflow用户
提问于 2021-03-13 18:05:41
回答 1查看 93关注 0票数 0

在我的硬视图布局中,我放置了一个约束布局,即不滚动的NestedScrollView。我搜索过堆叠溢出,什么都没用。这个cardView布局稍后放在RecyclerView中,如果这很重要的话。下面我还发布了布局蓝图。其中只有一部分显示在回收器视图中,用户单击的浮动操作按钮视图正在扩展。问题出在哪里?

代码语言:javascript
运行
复制
<androidx.constraintlayout.widget.ConstraintLayout
    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_margin="10dp"
    android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:id="@+id/main_cardview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">



        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/entire_card_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="@+id/main_cardview">

            <!--This is a ConstraintLayout for the fixed portion
                of the CardView. The elements
                that lie within the fixed portion of the CardView
                can be constrained to this layout.-->

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/fixed_container"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@color/teal_700"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0">

                <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab_expand"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:background="#FFFFFF"
                    android:backgroundTint="@color/white"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.954"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.888"
                    app:srcCompat="@drawable/ic_baseline_expand_more_24" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/hidden_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="gone"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@id/fixed_container"
                tools:visibility="visible">

                <androidx.core.widget.NestedScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fillViewport="true"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="parent">

                    <com.google.android.material.textview.MaterialTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/lorem_ipsum_long" />


                </androidx.core.widget.NestedScrollView>
            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.cardview.widget.CardView>


</androidx.constraintlayout.widget.ConstraintLayout>

布局蓝图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-15 13:19:07

你的代码运行良好。稍微修改了一下。请检查一下。

代码语言:javascript
运行
复制
<androidx.constraintlayout.widget.ConstraintLayout
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_margin="10dp"
android:layout_height="wrap_content">

<androidx.cardview.widget.CardView
    android:id="@+id/main_cardview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">



    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/entire_card_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/main_cardview">

        <!--This is a ConstraintLayout for the fixed portion
            of the CardView. The elements
            that lie within the fixed portion of the CardView
            can be constrained to this layout.-->

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/fixed_container"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@color/teal_700"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0">

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_expand"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:background="#FFFFFF"
                android:backgroundTint="@color/white"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.954"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.888"
                app:srcCompat="@drawable/ic_launcher_foreground"
                android:layout_marginRight="16dp"
                tools:ignore="VectorDrawableCompat" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/hidden_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@id/fixed_container"
            tools:visibility="visible">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="parent">
                    <com.google.android.material.textview.MaterialTextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/lorem_ipsum_long"
                        android:layout_marginBottom="16dp"/>


            </androidx.core.widget.NestedScrollView>
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.cardview.widget.CardView>


</androidx.constraintlayout.widget.ConstraintLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66616873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档