我正在使用嵌套Scrollview来包装recyclerview和其他按钮.它工作得很好,但我注意到,当我滚动它不顺利.请指导如何使滚动顺畅.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_filter"
android:text="Filter"
android:id="@+id/btn_filter"
android:layout_margin="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_sortbyt"
android:layout_margin="0dp"
android:text="Sort By"
android:id="@+id/btn_sortby"
android:layout_weight="1"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastest_product_list"
android:nestedScrollingEnabled="false"
android:isScrollContainer="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
Man*_*n K 20
尝试以下代码:
RecyclerView recycleView = (RecyclerView) findViewById(R.id.lastest_product_list);
recycleView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)
您可以修改布局
<ScrollView>
<LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastest_product_list"
android:nestedScrollingEnabled="false"
android:isScrollContainer="false">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请点击此处链接:ScrollView内的Recyclerview不能顺利滚动
Tej*_*oid 20
根据Android SDK的文档,
android:nestedScrollingEnabled="false"如果您使用的是Android API级别> = 21,则可行.
但是现在,人们也希望21以下的应用程序支持,所以在嵌套的scrollview内部循环滚动循环视图的另一个最佳解决方案是21以下和以上
Android API level >= 21
小智 4
为了平滑滚动,您可以更改在回收器视图编码中设置的布局管理器。我希望它有帮助。
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity()) {
@Override
public boolean canScrollVertically() {
return false;
}
};
recyclerView.setLayoutManager(layoutManager);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12382 次 |
| 最近记录: |