首页 > 解决方案 > 滚动在android底页内不起作用

问题描述

我正在尝试创建一个在 2 个片段之间切换的底部表,每个片段中都有一个滚动视图。第一个片段的 FrameLayout 的滚动视图有效,但不适用于第二个片段的 FrameLayout。

这是我到目前为止的代码:

bottom_sheet.xml

<LinearLayout 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:elevation="@dimen/design_appbar_elevation"
    android:id="@+id/my_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:clickable="true"
    style="?attr/bottomSheetStyle"
    app:behavior_fitToContents="false"
    app:behavior_hideable="false"
    app:behavior_peekHeight="@dimen/collapsed_height"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/grabber_height">

        <View
            android:layout_width="@dimen/grabber_handle_width"
            android:layout_gravity="top|center_horizontal"
            android:background="@drawable/bottomsheet_grabber_drawable"
            android:layout_marginTop="@dimen/grabber_handle_top_margin"
            android:layout_height="@dimen/grabber_handle_height"/>
    </FrameLayout>

// There is a scroll view inside this for which the scroll works
    <FrameLayout
        android:id="@+id/first_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/first_container_collapsed_height">
    </FrameLayout>

// There is a scroll view inside this for which the scroll does not work
    <FrameLayout
        android:id="@+id/second_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>

</LinearLayout>

first_container.xml

<LinearLayout 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:orientation="vertical">

    <LinearLayout
        android:id="@+id/top_filters_row_pills_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/top_row_container_height"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:scrollbars="none" />
    <androidx.core.widget.NestedScrollView
        android:id="@+id/sub_items_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

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

            <LinearLayout
                android:id="@+id/sub_items_item_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <androidx.cardview.widget.CardView
        android:id="@+id/buttons_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_row_buttons_container_height"
        app:cardElevation="2dp">

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

            <View
                android:id="@+id/divider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/divider" />

            <LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginHorizontal="@dimen/control_panel_buttons_horizontal_margin"
                android:gravity="center"
                android:orientation="horizontal">

                <androidx.appcompat.widget.AppCompatButton
                    android:id="@+id/clear_button"
                    style="@style/Button.Tertiary"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/control_panel_clear_all_filters" />

                <androidx.appcompat.widget.AppCompatButton
                    android:id="@+id/done_button"
                    style="@style/Button.Primary"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/buttons_spacing"
                    android:layout_weight="1"
                    android:text="@string/done" />
            </LinearLayout>
        </LinearLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>

second_container.xml 这呈现在 bottomSheet.xml 中的第二个 FrameLayout

<LinearLayout 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:orientation="vertical">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/another_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:text="@string/large_text" />
</LinearLayout>
</ScrollView>
</LinearLayout>

底片大致如何

底片大致如何

那里的Android专家可以帮助我解决这个问题吗?

标签: androidandroid-scrollviewandroid-nestedscrollview

解决方案


推荐阅读