android - 无法使用回收视图在 ScrollVIew/NestedScrollView 内滚动 ViewPager
问题描述
我有片段,其中包含一个嵌套滚动视图。在这个嵌套滚动视图中有一个视图分页器和回收视图。当我滚动视图时,只回收视图滚动,视图分页器不滚动。我想滚动回收视图和视图分页器。我尝试了很多方法,但没有成功。请帮助我.....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/tools"
android:id="@+id/timeline_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical"
android:tag="timeline_fragment">
<androidx.core.widget.NestedScrollView
android:id="@+id/nst_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/crv_profile_visit"
android:layout_weight="1"
android:fillViewport="true"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_view_pager"
android:layout_width="match_parent"
android:layout_height="@dimen/_140sdp"
android:visibility="gone"">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<!-- <com.customView.CustomViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:nestedScrollingEnabled="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
-->
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
<com.ViewPagerWithIndicator.TimelineFragmentViewPageWithIndicator
android:id="@+id/timelineViewPagerWithIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
app:arrow.enable="true"
app:arrow.height_="50dip"
app:arrow.width_="50dip"
app:left_arrow.drawable="@drawable/arrow_left_promotion"
app:right_arrow.drawable="@drawable/arrow_right_promotion"
app:round.color.default="@android:color/white"
app:round.color.selected="@android:color/holo_blue_light"
app:round.drawable="@drawable/background_rounded_view_pager_indicater"
app:round.enable="true"
app:round.size="15dip">
</com.ViewPagerWithIndicator.TimelineFragmentViewPageWithIndicator>
</RelativeLayout>
<ImageView
android:id="@+id/img_no_feed"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:layout_centerInParent="true"
android:visibility="gone" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycleview_user_time_line"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/_3sdp"
android:nestedScrollingEnabled="true" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="@+id/ll_create_post"
android:layout_width="@dimen/_170sdp"
android:layout_height="@dimen/_200sdp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_poll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_margin="8dp"
android:gravity="center"
android:text="@string/txt_timeline_fragment_poll"
android:textColor="@android:color/holo_red_dark"
android:visibility="invisible"
app:backgroundTint="@android:color/holo_orange_light"
app:rippleColor="@android:color/holo_red_light" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_margin="8dp"
android:gravity="center"
android:text="@string/txt_timeline_fragment_post"
android:textColor="@android:color/white"
android:visibility="invisible"
app:backgroundTint="@android:color/holo_orange_light"
app:rippleColor="@android:color/holo_red_light" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_margin="8dp"
android:textColor="@android:color/holo_red_dark"
app:backgroundTint="@android:color/holo_orange_light"
app:icon="@drawable/ic_float_button"
app:iconTint="@android:color/white"
app:rippleColor="@android:color/holo_red_light" />
</LinearLayout>
</RelativeLayout>
解决方案
删除 NestedScrollView,使用方法ListView
代替RecyclerView
并将 viewpager 放在 listview 的标题中addHeaderView
。
推荐阅读
- javascript - 来自全局组件的 Vue/Nuxt 访问函数
- excel - 检查某个文本框是否为空,然后在 VBA 中运行事件
- reactjs - 反应选择没有使用打字稿获取我选择的值
- android - 如何从 CoroutineScope Kotlin 返回一个 int?
- r - 将 3 个模型指标与 ggplot2 进行比较
- vue.js - 单击事件未在 antd 菜单项中触发
- python - 在重复调用的函数中下载数据时的内存管理
- java - Java中2个进程的生产者-消费者问题
- .htaccess - 如果重写规则匹配重定向,.htaccess 在新服务器上不起作用
- node.js - Angular 构建抛出错误 (JSON.parse(stripJsonComments(content)))