【问题标题】:Parent NestedScrollView containing viewpager do not scroll包含 viewpager 的父 NestedScrollView 不滚动
【发布时间】:2019-01-05 13:17:28
【问题描述】:

我有一个活动,其中有一个nestedscrollview,里面是一个视图寻呼机视图寻呼机有一个片段,片段有一个nestedscrollview。下面是结构:

<LinearLayout>
  <NestedScrollView (Parent)
    android:layout_width="match_parent"
    android:id="@+id/parent_scroll"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants"
    android:fillViewport="true">
    <LinearLayout << Stuck layout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">
        <TextView />
      </LinearLayout>
      <cViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
  </NestedScrollView>
</LinearLayout>

视图内部有一个片段。片段的布局如下:

<NestedScrollView (inside fragment, child)
  android:id="@+id/nestedScrollView"
  android:layout_width="match_parent"
  android:descendantFocusability="blocksDescendants"
  android:paddingBottom="40dp"
  android:layout_height="wrap_content"
  android:fillViewport="true"
  android:scrollbars="none"
  app:layoutManager="android.support.v7.widget.LinearLayoutManager">


  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:orientation="vertical"/>
</NestedScrollView>

问题

当尝试滚动子视图(片段内的 NestedScrollView)时,它会滚动,但活动内的父嵌套滚动视图不会滚动。 我已经实现了协调器布局,但存在一个问题。在抛出整个布局时会卡住。但是在缓慢滚动时有效,因此将其删除。

如果需要更多代码,请告诉我。

【问题讨论】:

    标签: android android-fragments android-viewpager android-nestedscrollview


    【解决方案1】:

    删除LinearLayout,它是您的NestedScrollView 的父级。然后对您的 NestedScrollView 进行此更改:

    <android.support.v4.widget.NestedScrollView
       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:id="@+id/nestedScrollView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:layout_behavior="@string/appbar_scrolling_view_behavior">
    

    这里是人们已经讨论过的this issue

    【讨论】:

    • 谢谢,但它不起作用。 schemas.android.com/apk/res/android" xmlns:app="schemas.android.com/apk/res-auto" android:id="@+id/parent_scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport=" true" app:layout_behavior="@string/appbar_scrolling_view_behavior"> 没有 android:fillViewport="true" 没有任何内容出现在视图寻呼机中。
    • 等一下,我会在我的 Android Studio 中查看您的问题。我将编辑我的答案。
    猜你喜欢
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多