如何解决无法在带有回收视图的ScrollVIew / NestedScrollView中滚动ViewPager
我有其中包含嵌套滚动视图的片段。在此嵌套滚动视图中有一个View Pager和回收视图。当我滚动视图时,仅回收视图滚动,View Pager不滚动。我想滚动回收视图和View寻呼器。我尝试了很多方法,但没有成功。请帮助我.....
<?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
,并使用addHeaderView
方法将viewpager放在listview的标题中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。