简体   繁体   English

NestedScrollView 内的 Viewpager 不滚动

[英]Viewpager inside NestedScrollView not scrolling

I want to scroll viewpager and RecyclerView together in NestedScrollView.我想在 NestedScrollView 中一起滚动 viewpager 和 RecyclerView。 ViewPager is not scrolling with NestedScrollView. ViewPager 不使用 NestedScrollView 滚动。 Here is my XML :这是我的 XML:

<android.support.v4.widget.NestedScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/scrollview"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true"
  tools:context="com.nobakhti.haidar.nosazimadares.MainActivity">

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

    <android.support.v4.view.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="250dp"
      android:layout_gravity="top"/>

    <me.relex.circleindicator.CircleIndicator
      android:id="@+id/indicator"
      android:layout_width="match_parent"
      android:layout_height="15dp"
      android:layout_alignBottom="@+id/pager"
      android:layout_alignParentStart="true"
      android:layout_marginBottom="2dp"
      android:layout_alignParentLeft="true"/>

    <android.support.v7.widget.RecyclerView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layoutDirection="ltr"
      tools:listitem="@layout/adapter_titles"
      android:id="@+id/news_title"/>

  </LinearLayout>

</android.support.v4.widget.NestedScrollView>

Here attaching the screenshot:这里附上截图:

在此处输入图片说明

Wrap NestedScrollView using CoordinatorLayout Like this像这样使用CoordinatorLayout包裹NestedScrollView

<androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.nobakhti.haidar.nosazimadares.MainActivity"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

      <android.support.v4.widget.NestedScrollView

      android:id="@+id/scrollview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fillViewport="true">

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

        <android.support.v4.view.ViewPager
          android:id="@+id/pager"
          android:layout_width="match_parent"
          android:layout_height="250dp"
          android:layout_gravity="top"/>

        <me.relex.circleindicator.CircleIndicator
          android:id="@+id/indicator"
          android:layout_width="match_parent"
          android:layout_height="15dp"
          android:layout_alignBottom="@+id/pager"
          android:layout_alignParentStart="true"
          android:layout_marginBottom="2dp"
          android:layout_alignParentLeft="true"/>

        <android.support.v7.widget.RecyclerView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layoutDirection="ltr"
          tools:listitem="@layout/adapter_titles"
          android:id="@+id/news_title"/>

      </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

Replace NestedScrollView with ScrollView .ScrollView替换NestedScrollView That should work.那应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM