日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android Android-PullToRefresh 下拉刷新

發布時間:2024/9/30 Android 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android Android-PullToRefresh 下拉刷新 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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>


?常用的方法

package com.example.aa; import java.util.ArrayList; import java.util.List; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; import android.support.v7.app.ActionBarActivity; import android.text.format.DateUtils; import android.widget.ListView; import android.widget.Toast; import android.os.AsyncTask; import android.os.Bundle;public class MainActivity extends ActionBarActivity {PullToRefreshListView pullToRefreshListView ;ListView listView ;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);pullToRefreshListView = (PullToRefreshListView) findViewById( R.id.listview ) ;pullToRefreshListView.setOnRefreshListener( new OnRefreshListener<ListView>() {@Overridepublic void onRefresh(PullToRefreshBase<ListView> refreshView) {String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL ) ; //最后一次刷新的時間refreshView.getLoadingLayoutProxy().setLastUpdatedLabel( "上次刷新時間 " + label); //設置刷新圖標 下拉的時候顯示的內容 refreshView.getLoadingLayoutProxy().setLoadingDrawable(getResources().getDrawable( R.drawable.ic_launcher) );//下拉完成后,還沒有刷新時 顯示的內容refreshView.getLoadingLayoutProxy().setReleaseLabel( "默默地么么噠!!" );//松開手,正在刷新時 ,顯示的內容refreshView.getLoadingLayoutProxy().setRefreshingLabel( "啦啦啦啦啦" );Toast.makeText( MainActivity.this , "刷新了", Toast.LENGTH_SHORT ).show(); new GetDataTask().execute( ) ;}});//listview 滑到 最后一項pullToRefreshListView.setOnLastItemVisibleListener( new OnLastItemVisibleListener() {@Overridepublic void onLastItemVisible() {Toast.makeText( MainActivity.this , "listview到底了", Toast.LENGTH_SHORT ).show() ; }});pullToRefreshListView.setMode( Mode.PULL_FROM_START );listView = pullToRefreshListView.getRefreshableView() ;listView.setAdapter( new Adapter( this , getData() ));/*** 程序進來就執行刷新數據,自動執行刷新*/pullToRefreshListView.setRefreshing(); }/*** @author admin* pullToRefreshListView.onRefreshComplete(); 這一句最好放在異步里面寫 * */private class GetDataTask extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... params) { try { Thread.sleep( 500 ); } catch (InterruptedException e) { } return "" ; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); pullToRefreshListView.onRefreshComplete(); } } List<String> getData(){List<String> list = new ArrayList<String>() ;for( int i = 0 ; i < 100 ; i ++) {list.add( "ddd") ;}return list ;}}

?

???刷新模式

//向下拉 pullToRefreshListView.setMode( Mode.PULL_FROM_START );//向上拉 pullToRefreshListView.setMode( Mode.PULL_FROM_END );//同時使用 下拉 和 上拉 pullToRefreshListView.setMode( Mode.BOTH );/不啟用刷新功能pullToRefreshListView.setMode( Mode.DISABLED );

??

?? ?獲取當前的刷新模式

//獲取當前的刷新模式 if( pullToRefreshListView.getMode() == Mode.BOTH ){Toast.makeText( MainActivity.this , "當前的刷新模式是 " + pullToRefreshListView.getMode() ,Toast.LENGTH_SHORT ).show(); }

?

?? 設置刷新時的聲音

/*** 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);

?

?

?設置 下拉刷新 和 上拉加載 更多 的監聽方法

pullToRefreshListView.setOnRefreshListener( new Refresh() ) ;/*** 監聽方法* @author admin*/class Refresh implements OnRefreshListener2<ListView> {//下拉 @Overridepublic void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {}//上拉 @Overridepublic void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {}}

????

???? ?設置正在刷新時,listview是否可以滾動

//正在刷新的時候,listView 禁止滾動pullToRefreshListView.setScrollingWhileRefreshingEnabled( false );//正在刷新的時候,listView 可以滾動pullToRefreshListView.setScrollingWhileRefreshingEnabled( true );

?

?? 設置刷新時顯示的字體的顏色

<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 刷新提示子選項顏色值 --></LinearLayout>

?? 運行結果

?

?

分別設置 下拉 和 上拉 顯示的字體

//得到下拉時候顯示的ILoadingLayoutILoadingLayout startLayout = pullToRefreshListView.getLoadingLayoutProxy( true , false ) ; startLayout.setPullLabel("你可勁拉,拉...下拉");// 剛下拉時,顯示的提示 startLayout.setRefreshingLabel("好嘞,正在刷新...下拉");// 刷新時 startLayout.setReleaseLabel("你敢放,我就敢刷新...下拉");// 下來達到一定距離時,顯示的提示 //得到上拉時候顯示的ILoadingLayoutILoadingLayout endLayout = pullToRefreshListView.getLoadingLayoutProxy( false , true ) ;endLayout.setPullLabel("你可勁拉,拉... 上拉");// 剛下拉時,顯示的提示 endLayout.setRefreshingLabel("好嘞,正在刷新...上拉");// 刷新時 endLayout.setReleaseLabel("你敢放,我就敢刷新...上拉");// 下來達到一定距離時,顯示的提示

?

???? 常用的 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 刷新提示子選項顏色值 --><!-- ptr:ptrHeaderBackground 上拉背景圖 --><!-- ptrShowIndicator 右上角顯示的小圖標 --><!-- ptrRefreshableViewBackground 整個listview的背景 --><!-- ptrScrollingWhileRefreshingEnabled 刷新的時候,是否允許ListView或GridView滾動。覺得為true比較好。 --><!-- ptrListViewExtrasEnabled Footer以何種方式加入mPullRefreshListView,true為headView方式加入,就是滾動時刷新頭部會一起滾動。 --><!-- ptrRotateDrawableWhilePulling 當動畫設置為rotate時,下拉是是否旋轉。 --><!-- ptr:ptrAnimationStyle 的取值:flip(翻轉動畫), rotate(旋轉動畫) 。 --><!-- ptr:ptrDrawable 則就是設置圖標了。 --></LinearLayout>

?

?運行結果

?

?3、不太常用的東西

? ?1、如何 關閉 log 日志輸出 ?

???? PullToRefresh 默認是開啟日志輸出的 。 在? PullToRefreshBase 里面可以看到 static final boolean DEBUG = true ;?

????? true : 輸出日志 。?? false : 不輸出日志

總結

以上是生活随笔為你收集整理的android Android-PullToRefresh 下拉刷新的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。