在 activity 中滚动多个回收器视图。 (如何让它光滑)
Scrolling of multiple recycler view in an activity. (how to make it smooth)
我的 activity 中有 2 个 recyclerviews,第一个是水平滚动的,第二个是垂直滚动的。 (XML 代码如下)
但是滚动不流畅
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:clickable="true"
>
<ProgressBar
android:id="@+id/progressBarCircularIndetermininatesearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/progressbacklin"
android:scrollbars="none"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentTop="true"
android:scrollbars="none"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_below="@+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:scrollbars="none"
/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="@+id/progressbacklin"
android:layout_above="@+id/adViewsearch"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginBottom="90dp"
android:layout_marginTop="5dp"
android:background="@drawable/white"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
>
<ProgressBar
android:id="@+id/progressBarCircularIndetermininate"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewsearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
</RelativeLayout>
我用
setNestedScrollingEnabled(false);
对于两个回收者视图。
有什么想法可以通过平滑滚动来实现吗?
将 ScrollView
更改为 NestedScrollView
。
为了使其正常工作,您需要在 NestedScrollView
内设置高度为 wrap_content
的 RecyclerView
,并且需要从代码中设置 recyclerView.setNestedScrollingEnabled(false)
。
我解决这个问题的方法是使用一个 Recycler 视图而不是两个,并将另一个(有问题的第一个 recycler 视图)recycler 视图设置为它的第一项。
现在它运行完美,滚动流畅。
我的 activity 中有 2 个 recyclerviews,第一个是水平滚动的,第二个是垂直滚动的。 (XML 代码如下) 但是滚动不流畅
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:clickable="true"
>
<ProgressBar
android:id="@+id/progressBarCircularIndetermininatesearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/progressbacklin"
android:scrollbars="none"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentTop="true"
android:scrollbars="none"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_below="@+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:scrollbars="none"
/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="@+id/progressbacklin"
android:layout_above="@+id/adViewsearch"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginBottom="90dp"
android:layout_marginTop="5dp"
android:background="@drawable/white"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
>
<ProgressBar
android:id="@+id/progressBarCircularIndetermininate"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewsearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
</RelativeLayout>
我用
setNestedScrollingEnabled(false);
对于两个回收者视图。
有什么想法可以通过平滑滚动来实现吗?
将 ScrollView
更改为 NestedScrollView
。
为了使其正常工作,您需要在 NestedScrollView
内设置高度为 wrap_content
的 RecyclerView
,并且需要从代码中设置 recyclerView.setNestedScrollingEnabled(false)
。
我解决这个问题的方法是使用一个 Recycler 视图而不是两个,并将另一个(有问题的第一个 recycler 视图)recycler 视图设置为它的第一项。 现在它运行完美,滚动流畅。