Gay*_*hri 1 android scrollview pull-to-refresh
我在PullToRefreshScrollview中有一个Listview,FrameLayout.我正在将一个片段加载到framelayout中.使用延迟适配器将数据加载到listview中.我可以在listview加载时看到fragment/framelayout.但是,在将数据加载到listview并且framelayout不可见之后,Scrollview会自动滚动到listview的位置.如何将滚动视图滚动到顶部?请帮我.提前致谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg"
android:orientation="vertical" >
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/ptrScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:paddingBottom="5dp"
ptr:ptrMode="pullUpFromBottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<com.xxxx.yyyy.CustomListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_bg"
android:focusable="false" />
<ProgressBar
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我采取的方法
让我们说你有这样的PullToRefreshScrollView的引用
PullToRefreshScrollView myRefreshScrollView = (PullToRefreshScrollView)findViewById(R.id. ptrScrollView);
Run Code Online (Sandbox Code Playgroud)
要获取ACTUAL ScrollView对象,您需要像这样调用getRefreshableView()
ScrollView myScrollView = myRefreshScrollView.getRefreshableView();
Run Code Online (Sandbox Code Playgroud)
然后滚动此对象
myScrollView.scrollTo(0,0);
Run Code Online (Sandbox Code Playgroud)
要么
myScrollView.smoothScrollTo(0,0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1454 次 |
| 最近记录: |