
SwipeRefreshLayout
SwipeRefreshLayout 可以用于通过下滑的手势刷新View内容的情况。使用起来很简单,用SwipeRefreshLayout包裹需要刷新的View即可。
bash
<android.support.v4.widget.SwipeRefreshLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/swipe_container"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayout android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><ListViewandroid:id="@android:id/list"style="@style/ListView"android:layout_width="match_parent"android:layout_height="match_parent" /></LinearLayout></android.support.v4.widget.SwipeRefreshLayout>
初始化View的Activity应该注册一个OnRefreshListener来处理手势完成时需要执行的(刷新)动作。当手势结束的时候,Refreshing指示器会一直显示,如果监听者决定不刷新,或者已经刷新完了,那么要调用setRefreshing(false)来取消Refreshing指示器。如果Activity需要单独显示Refreshing指示器,也可以调用setRefreshing(true)。
这个Layout应该作为需要刷新内容的父视图,并且只支持一个子视图。这个子视图将成为手势的目标,并且会被强制匹配SwipeRefreshLayout的宽高。
SwipeRefreshLayout不提供可访问的事件;因此,应该提供一个菜单项来允许,当滑动手势时刷新内容。
不知道是不是TextView自己有处理滚动的原因或者其他,SwipeRefreshLayout单独和TextView使用时会很奇怪,往下滑动时Refreshing指示器不会正常显示,只有到松手时,才会突然出现一次又消失。解决这个问题可以通过在TextView外面在包括一个ScollView。
bash
<android.support.v4.widget.SwipeRefreshLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/swipe_container"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayout android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><ListViewandroid:id="@android:id/list"style="@style/ListView"android:layout_width="match_parent"android:layout_height="match_parent"android:visibility="gone" /><ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent" ><TextViewandroid:id="@android:id/empty"style="@style/ListSubtitleText"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_gravity="center"android:text="@string/default_empty" /></ScrollView></LinearLayout></android.support.v4.widget.SwipeRefreshLayout>
评论
新的评论
上一篇
spring-android-auth ClientHttpRequest
问题 使用spring-android-auth时,其使用的 RestTemplate 是依赖包 spring-android-rest-template 中的,而是spring-web-mvc中的。该 RestTemplate 使用http request默认的逻辑如下 使用…
下一篇
Fatal signal 11
错误 多个 AsyncTask 、 Loader 同时执行的时候,偶尔会闪退。 错误信息大致如下: 原因 Stackoverflow上有一个类型的 问题 ,但是它的原因是在多个线程中调用了 BluetoothSocket#close 方法。回到自己的问题上来,我这边发生的问题也…
