使ScrollView的初始位置置顶

xiaoxiao2021-02-28  60

1.在Java程序中添加如下代码,注意如果scrollview中嵌套有recyclerview,listview,gridview之类的控件,请将下列代码放在listview初始化之后的位置。

 

//设置scrollview初始化后滑动到顶部,必须在gridview填充数据之后,否则无法实现预期效果 firstPage_scrollView.smoothScrollTo(0,20); firstPage_scrollView.setFocusable(true);

 

2.xml中,在父元素的属性下面下下面这两行即可。

android:focusableInTouchMode="true" android:focusable="true"

 

<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout android:id="@+id/refresh_ll" android:layout_width="match_parent" android:focusableInTouchMode="true" android:focusable="true" android:layout_height="match_parent" android:layout_below="@+id/ll_top"> <ScrollView android:scrollbars="none" android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="match_parent">

 

还有一种方法  直接设置scrollview里面的listview  或者recyclerview等setFocusable(false)

list1.setFocusable(false); scrollview.fullScroll(ScrollView.FOCUS_UP);

 

 

 

 

转载请注明原文地址: https://www.6miu.com/read-57806.html

最新回复(0)