【发布时间】:2018-05-22 09:37:29
【问题描述】:
我在嵌套滚动视图中实现了一个循环视图。但是回收视图滚动到位置方法不起作用。
下面是我的示例代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
下面是滚动的方法
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(this) {
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(pos);
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
【问题讨论】:
-
但是为什么你在 NestedScrollView 中使用了 RecyclerView?
-
因为我在recycleview之外还有一些其他的看法
-
@Darshana 测试尝试
ViewCompat.setNestedScrollingEnabled(recyclerView,false);而不是stackoverflow.com/a/45190337/7666442 -
@NileshRathod 不适合我
-
@Darshana 如何解决这个问题?如果您得到解决方案,请发布您的答案谢谢!
标签: android