android Android-PullToRefresh 下拉刷新
生活随笔
收集整理的這篇文章主要介紹了
android Android-PullToRefresh 下拉刷新
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、github下載地址
???????????原作者:? https://github.com/chrisbanes/Android-PullToRefresh
???????????我自己的:??https://github.com/zyj1609wz/Android-PullToRefresh
2、使用方法
???? listview? 布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.aa.MainActivity"tools:ignore="MergeRootFrame" ><com.handmark.pulltorefresh.library.PullToRefreshListViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/listview"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"android:listSelector="#00000000"ptr:ptrMode="both" /></LinearLayout>
?常用的方法
?
???刷新模式
//向下拉 pullToRefreshListView.setMode( Mode.PULL_FROM_START );//向上拉 pullToRefreshListView.setMode( Mode.PULL_FROM_END );//同時使用 下拉 和 上拉 pullToRefreshListView.setMode( Mode.BOTH );/不啟用刷新功能pullToRefreshListView.setMode( Mode.DISABLED );??
?? ?獲取當(dāng)前的刷新模式
//獲取當(dāng)前的刷新模式 if( pullToRefreshListView.getMode() == Mode.BOTH ){Toast.makeText( MainActivity.this , "當(dāng)前的刷新模式是 " + pullToRefreshListView.getMode() ,Toast.LENGTH_SHORT ).show(); }?
?? 設(shè)置刷新時的聲音
/*** Add Sound Event Listener*/SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.a1 ); //開始刷新顯示的聲音 soundListener.addSoundEvent(State.RESET, R.raw.a2 ); //刷新完成后,顯示的聲音 soundListener.addSoundEvent(State.REFRESHING, R.raw.a3 ); //正在刷新顯示的聲音pullToRefreshListView.setOnPullEventListener(soundListener);?
?
?設(shè)置 下拉刷新 和 上拉加載 更多 的監(jiān)聽方法
pullToRefreshListView.setOnRefreshListener( new Refresh() ) ;/*** 監(jiān)聽方法* @author admin*/class Refresh implements OnRefreshListener2<ListView> {//下拉 @Overridepublic void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {}//上拉 @Overridepublic void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {}}????
???? ?設(shè)置正在刷新時,listview是否可以滾動
//正在刷新的時候,listView 禁止?jié)L動pullToRefreshListView.setScrollingWhileRefreshingEnabled( false );//正在刷新的時候,listView 可以滾動pullToRefreshListView.setScrollingWhileRefreshingEnabled( true );?
?? 設(shè)置刷新時顯示的字體的顏色
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.aa.MainActivity"tools:ignore="MergeRootFrame" ><com.handmark.pulltorefresh.library.PullToRefreshListViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/listview"android:background="#ffffff"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"android:listSelector="#00000000"ptr:ptrHeaderTextColor="#FF9900"ptr:ptrHeaderSubTextColor="#330099"ptr:ptrMode="both" /><!-- ptrHeaderTextColor 刷新提示顯示的顏色 --><!-- ptrHeaderSubTextColor 刷新提示子選項(xiàng)顏色值 --></LinearLayout>?? 運(yùn)行結(jié)果
?
?
分別設(shè)置 下拉 和 上拉 顯示的字體
//得到下拉時候顯示的ILoadingLayoutILoadingLayout startLayout = pullToRefreshListView.getLoadingLayoutProxy( true , false ) ; startLayout.setPullLabel("你可勁拉,拉...下拉");// 剛下拉時,顯示的提示 startLayout.setRefreshingLabel("好嘞,正在刷新...下拉");// 刷新時 startLayout.setReleaseLabel("你敢放,我就敢刷新...下拉");// 下來達(dá)到一定距離時,顯示的提示 //得到上拉時候顯示的ILoadingLayoutILoadingLayout endLayout = pullToRefreshListView.getLoadingLayoutProxy( false , true ) ;endLayout.setPullLabel("你可勁拉,拉... 上拉");// 剛下拉時,顯示的提示 endLayout.setRefreshingLabel("好嘞,正在刷新...上拉");// 刷新時 endLayout.setReleaseLabel("你敢放,我就敢刷新...上拉");// 下來達(dá)到一定距離時,顯示的提示?
???? 常用的 xml 配置
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.aa.MainActivity"tools:ignore="MergeRootFrame" ><com.handmark.pulltorefresh.library.PullToRefreshListViewxmlns:ptr="http://schemas.android.com/apk/res-auto"android:id="@+id/listview"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#ffffff"android:gravity="center"android:listSelector="#00000000"ptr:ptrHeaderBackground="@drawable/background"ptr:ptrHeaderSubTextColor="#330099"ptr:ptrHeaderTextColor="#B26B00"ptr:ptrListViewExtrasEnabled="false"ptr:ptrMode="both"ptr:ptrRefreshableViewBackground="@drawable/b2"ptr:ptrRotateDrawableWhilePulling="false"ptr:ptrScrollingWhileRefreshingEnabled="true"ptr:ptrShowIndicator="true" /><!-- ptrHeaderTextColor 刷新提示顯示的顏色 --><!-- ptrHeaderSubTextColor 刷新提示子選項(xiàng)顏色值 --><!-- ptr:ptrHeaderBackground 上拉背景圖 --><!-- ptrShowIndicator 右上角顯示的小圖標(biāo) --><!-- ptrRefreshableViewBackground 整個listview的背景 --><!-- ptrScrollingWhileRefreshingEnabled 刷新的時候,是否允許ListView或GridView滾動。覺得為true比較好。 --><!-- ptrListViewExtrasEnabled Footer以何種方式加入mPullRefreshListView,true為headView方式加入,就是滾動時刷新頭部會一起滾動。 --><!-- ptrRotateDrawableWhilePulling 當(dāng)動畫設(shè)置為rotate時,下拉是是否旋轉(zhuǎn)。 --><!-- ptr:ptrAnimationStyle 的取值:flip(翻轉(zhuǎn)動畫), rotate(旋轉(zhuǎn)動畫) 。 --><!-- ptr:ptrDrawable 則就是設(shè)置圖標(biāo)了。 --></LinearLayout>?
?運(yùn)行結(jié)果
?
?3、不太常用的東西
? ?1、如何 關(guān)閉 log 日志輸出 ?
???? PullToRefresh 默認(rèn)是開啟日志輸出的 。 在? PullToRefreshBase 里面可以看到 static final boolean DEBUG = true ;?
????? true : 輸出日志 。?? false : 不輸出日志
總結(jié)
以上是生活随笔為你收集整理的android Android-PullToRefresh 下拉刷新的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GitHub 基本常用知识解答
- 下一篇: 苹果开发基础知识