【发布时间】:2016-12-03 12:48:38
【问题描述】:
这是我的 xml 代码。
<android.support.v4.widget.NestedScrollView
android:id="@+id/nav_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/nav_list"
android:layout_width="match_parent"
android:layout_height="@dimen/weight_based_height"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
我试过了
navigationScroll.scrollTo(0, 200);
navigationScroll.smoothScrollTo(0, 200);
navigationRecycler.scrollTo(0, 200);
navigationRecycler.smoothScrollTo(0, 200)
它们都不起作用。什么都没有发生,根本没有滚动,nada。
但有趣的是,当我这样做时
navigationScroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY == 0) {
navigationScroll.scrollTo(0, 150);
}
}
});
navigationScroll.scrollTo(0, 150); 有效。你们认为我怎样才能让它工作而不必把它放在监听器中?
【问题讨论】:
-
我遇到了类似的问题。介意看看这个问题吗? stackoverflow.com/questions/53876952/…
标签: android android-recyclerview nestedscrollview android-nestedscrollview