【问题标题】:NestestedScrollView with RecycleView and ViewPager is not scrolled up viewsViewPager 中带有 RecyclerView 的 NestedScrollView 不会向上滚动视图
【发布时间】:2017-11-21 09:20:00
【问题描述】:

我正在尝试实现在包含 recycleview 和 viewpager 的 xml 布局中滚动视图,但由于某种原因,nestedScrollView 不会向上滚动视图。


布局文件。

 <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested_scroll"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:fillViewport="true"
        >


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


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen_200">


                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager_media"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />


                <RelativeLayout
                    android:id="@+id/viewPagerIndicator"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:gravity="center"
                    android:padding="@dimen/dimen_10">

                    <LinearLayout
                        android:id="@+id/viewPagerCountDots"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:gravity="center"
                        android:orientation="horizontal" />


                </RelativeLayout>


            </RelativeLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rc_media"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        </LinearLayout>

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

Java 文件


    mediaAdapter = new MediaDiscoverAdapter(getActivity(), mediaCallbackListener);
    discoverBinding.rcMedia.setNestedScrollingEnabled(false);
    discoverBinding.nestedScroll.setFillViewport(true);
    discoverBinding.rcMedia.setAdapter(mediaAdapter);
    layoutManager = new StickyHeaderLayoutManager();
    layoutManager.setAutoMeasureEnabled(true);
    discoverBinding.rcMedia.setLayoutManager(layoutManager);

【问题讨论】:

    标签: android android-recyclerview android-viewpager android-nestedscrollview


    【解决方案1】:

    我在StackOverFlow 的帮助下找到了解决方案。我只是使用getItemViewTypeRecycleViewRecycleView 的一部分作为行项目并删除了NestedScrollView 所以现在布局看起来像..

    mainLayout.xml

    <data>
    
        <variable
            name="MediaDiscoverFragmentNew"
            type="com.hpc.fragments.media.MediaDiscoverFragmentNew" />
    </data>
    
    
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rc_media"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    
    </android.support.v4.widget.SwipeRefreshLayout>
    

    并为顶部 Viewpager 创建了两个单独的项目 xmls raw_media_top.xml,为其余项目创建了另一个 raw_media.xml

          if(viewType == HEADER_VIEW) {
            RawMediaTopBinding mediaTopBinding = 
            DataBindingUtil.inflate(mLayoutInflater, R.layout.raw_media_top, parent, false);
            mediaTopBinding.setMediaDiscoverAdapterNew(this);
            return new HeaderViewHolder(mediaTopBinding);
        } else {
            RawMediaBinding inspirationItemsBinding = DataBindingUtil.inflate(mLayoutInflater, R.layout.raw_media, parent, false);
            inspirationItemsBinding.setMediaDiscoverAdapterNew(this);
            return new ItemViewHolder(inspirationItemsBinding);
        }
    

    干杯!

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 2020-04-28
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多