【问题标题】:Can't scroll ScrollView in NestedScrollView无法在 NestedScrollView 中滚动 ScrollView
【发布时间】:2017-08-02 15:14:23
【问题描述】:

我正在使用带有 BottomSheetBehavior 的 NestedScrollView。它有一个直接的孩子,一个 ScrollView。当底部的工作表展开时,我希望能够滚动浏览 ScrollView 中的内容,因为即使它展开了,不滚动也无法查看。但是,它没有响应。这是 XML:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.thunderbuild.weegnet.fragments.FragmentBridgesMap">

    <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/bridges_mv_map"
            app:mapType="normal" />

    <android.support.v4.widget.NestedScrollView
            android:id="@+id/bridges_nsv_sheet"
            android:layout_width="match_parent"
            android:elevation="4dp"
            android:layout_height="350dp"
            android:scrollbars="none"
            android:background="@android:color/white"
            android:clipToPadding="true"
            app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:id="@+id/bridge_sv_content">

            <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_constraintTop_toBottomOf="@+id/bridge_mv_map"
                    android:id="@+id/bridge_cl_content"
                    android:orientation="vertical">


                <TextView
                        android:id="@+id/bridge_tv_name"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:text="Bridge name"
                        android:textColor="@color/primaryTextColor"
                        android:textSize="20sp"
                        android:layout_marginTop="8dp"
                        android:layout_marginBottom="0dp"
                        app:layout_constraintBottom_toTopOf="@+id/linearLayout"
                        app:layout_constraintTop_toTopOf="parent"
                        android:layout_marginLeft="8dp"
                        app:layout_constraintLeft_toLeftOf="parent"
                        android:layout_marginRight="8dp"
                        app:layout_constraintRight_toRightOf="parent" />

                <Button
                        android:id="@+id/bridge_btn_weigh"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Weigh"
                        android:layout_gravity="center_horizontal"
                        android:background="@drawable/button_style"
                        android:textColor="@color/lightTextColor"
                        app:layout_constraintTop_toBottomOf="@+id/ll_opening_times"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintRight_toRightOf="parent"
                        android:layout_marginTop="8dp" />

                <TextView
                        android:id="@+id/bridge_tv_status"
                        android:layout_width="wrap_content"
                        android:textColor="@color/green"
                        android:layout_gravity="center_vertical"
                        android:layout_height="wrap_content"
                        android:text="Opened until..."
                        app:layout_constraintLeft_toLeftOf="@+id/bridge_tv_name"
                        app:layout_constraintTop_toBottomOf="@+id/bridge_tv_name"
                        android:layout_marginTop="8dp" />

                <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_marginRight="0dp"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintTop_toTopOf="@+id/bridge_tv_status"
                        app:layout_constraintBottom_toBottomOf="@+id/bridge_tv_status"
                        android:layout_marginEnd="8dp"
                        android:id="@+id/linearLayout">

                    <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:tint="@color/secondaryTextColor"
                            android:layout_marginRight="4dp"
                            android:src="@drawable/ic_car" />

                    <TextView
                            android:id="@+id/bridge_tv_eta"
                            android:layout_gravity="center_vertical|right"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="5 min." />
                </LinearLayout>

                <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_marker"
                        android:id="@+id/imageView"
                        android:tint="@color/colorPrimary"
                        android:layout_marginLeft="16dp"
                        app:layout_constraintLeft_toLeftOf="parent"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="16dp"
                        app:layout_constraintTop_toBottomOf="@+id/bridge_tv_status" />

                <LinearLayout
                        android:id="@+id/ll_opening_times"
                        android:orientation="vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:layout_constraintRight_toRightOf="parent"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/view"
                        android:layout_marginTop="8dp"
                        android:layout_marginLeft="8dp"
                        android:layout_marginRight="8dp" />

                <TextView
                        android:text="Address"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/bridge_tv_address"
                        app:layout_constraintLeft_toLeftOf="@+id/ll_opening_times"
                        app:layout_constraintBottom_toBottomOf="@+id/imageView"
                        app:layout_constraintTop_toTopOf="@+id/imageView" />

                <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_clock"
                        android:tint="@color/colorPrimary"
                        android:id="@+id/imageView2"
                        app:layout_constraintTop_toTopOf="@+id/ll_opening_times"
                        app:layout_constraintLeft_toLeftOf="@+id/imageView" />

                <View
                        android:layout_width="0dp"
                        android:layout_height="1dp"
                        android:background="@color/secondaryTextColor"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/bridge_tv_address"
                        app:layout_constraintRight_toRightOf="parent"
                        android:layout_marginTop="16dp"
                        app:layout_constraintHorizontal_bias="0.0"
                        android:id="@+id/view" />
            </android.support.constraint.ConstraintLayout>
        </ScrollView>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

我尝试了here 提到的解决方案,但无济于事。有谁知道如何解决这个问题?

编辑:我现在注意到我可以滚动,但还不够远。内容在底部被截断。

【问题讨论】:

  • NestedScrollView 是 Scrollview 的扩展类。它在你的 xml 中已经是多余的了。使用 NestedScrollView 代替
  • 不,NestedScrollView 扩展自 FrameLayout。但是,我仍然尝试了您的建议。我删除了子 ScrollView,但结果相同。即使完全展开,完整的内容也不适合底部的表格,所以我希望能够滚动它。我无法滚动。

标签: android scrollview bottom-sheet nestedscrollview


【解决方案1】:

其中一个问题是按钮没有底部约束。我添加了它,并且在它的底部添加了很多边距,这防止它被切断。这是一个草率的解决方案,但现在可以使用。

【讨论】:

    猜你喜欢
    • 2016-10-20
    • 2021-01-01
    • 1970-01-01
    • 2020-12-05
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    相关资源
    最近更新 更多