【问题标题】:Android NestedScrollView scroll does not workAndroid NestedScrollView 滚动不起作用
【发布时间】:2016-02-09 18:07:31
【问题描述】:

标题几乎说明了一切。 我有一个带有 FrameLayout 的 Activity,我在运行时添加了一个片段。片段中的数据显示正常,但我无法滚动。

Activity的布局是:

    <RelativeLayout android:id="@+id/content_layout" 
 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"
tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_scrollFlags="scroll|enterAlways" />

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

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

        <FrameLayout android:id="@+id/fl_content" android:layout_below="@id/toolbar"
            android:layout_width="match_parent" android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent" android:layout_height="match_parent"/>

        </FrameLayout>

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

</RelativeLayout>

片段的布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">

<ImageView android:id="@+id/iv_cover"
    android:layout_width="100dp" android:layout_height="100dp" />

<TextView android:id="@+id/tv_release_artistname"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_albumname"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_year"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_label"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_style"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView android:id="@+id/tv_release_notes"
    android:layout_width="wrap_content" android:layout_height="wrap_content" />

【问题讨论】:

    标签: android android-design-library


    【解决方案1】:

    您应该将NestedScrollView 设为FrameLayout 的父级,然后在FrameLayout 上添加您的Fragment

    现在,当您在上面添加 Fragment 时,您正在覆盖 FrameLayoutNestedScrollView 的内容。

    另外不要忘记切换后在NestedScrollView上加上behaviour

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      相关资源
      最近更新 更多