Android SwipeRefreshLayout下拉刷新源碼解析
本文實(shí)例為大家分享了SwipeRefreshLayout下拉刷新源碼,供大家參考,具體內(nèi)容如下
1.SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一個(gè)下拉刷新組件,實(shí)現(xiàn)刷新效果更方便。
弊端:只有下拉

//設(shè)置刷新控件圈圈的顏色 swipe_refresh_layout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_orange_light, android.R.color.holo_red_light, android.R.color.holo_green_light); //設(shè)置刷新控件背景色 swipe_refresh_layout.setProgressBackgroundColorSchemeColor(getResources().getColor(android.R.color.white)); //設(shè)置滑動(dòng)距離 swipe_refresh_layout.setDistanceToTriggerSync(100); //設(shè)置大小模式 swipe_refresh_layout.setSize(SwipeRefreshLayout.DEFAULT); //設(shè)置下拉刷新控件狀態(tài)隱藏 swipe_refresh_layout.setRefreshing(false);
2.在xml文件中引用android.support.v4.widget.SwipeRefreshLayout控件,在里面可以放置任何一個(gè)控件,例如ListView,gridview等。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/id_listview" android:layout_width="match_parent" android:layout_height="match_parent" > </ListView> </android.support.v4.widget.SwipeRefreshLayout> </RelativeLayout>
3.Java代碼
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout swipeLayout;
private ListView listView;
private ListViewAdapter adapter;
private List<ItemInfo> infoList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);
swipeLayout.setOnRefreshListener(this);
// 頂部刷新的樣式
swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,
android.R.color.holo_blue_bright, android.R.color.holo_orange_light);
infoList = new ArrayList<ItemInfo>();
ItemInfo info = new ItemInfo();
info.setName("coin");
infoList.add(info);
listView = (ListView) this.findViewById(R.id.listview);
adapter = new ListViewAdapter(this, infoList);
listView.setAdapter(adapter);
}
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
public void run() {
swipeLayout.setRefreshing(false);
ItemInfo info = new ItemInfo();
info.setName("coin-refresh");
infoList.add(info);
adapter.notifyDataSetChanged();
}
}, 500);
}
}
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 使用SwipeRefreshLayout控件仿抖音做的視頻下拉刷新效果
- Android SwipeRefreshLayout仿抖音app靜態(tài)刷新
- android使用SwipeRefreshLayout實(shí)現(xiàn)ListView下拉刷新上拉加載
- android基于SwipeRefreshLayout實(shí)現(xiàn)類QQ的側(cè)滑刪除
- Android SwipereFreshLayout下拉刷新
- Android SwipeRefreshLayout下拉刷新組件示例
- Android實(shí)現(xiàn)SwipeRefreshLayout首次進(jìn)入自動(dòng)刷新
- Android SwipeRefreshLayout超詳細(xì)講解
相關(guān)文章
Android開發(fā)實(shí)現(xiàn)控件雙擊事件的監(jiān)聽接口封裝類
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)控件雙擊事件的監(jiān)聽接口封裝類,需要的朋友可以參考下2020-03-03
Android實(shí)現(xiàn)兩個(gè)ScrollView互相聯(lián)動(dòng)的同步滾動(dòng)效果代碼
這篇文章主要介紹了Android實(shí)現(xiàn)兩個(gè)ScrollView互相聯(lián)動(dòng)的同步滾動(dòng)效果代碼,涉及Android操作ScrollView實(shí)現(xiàn)聯(lián)動(dòng)功能的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
解析ScrollView--仿QQ空間標(biāo)題欄漸變
本篇文章主要介紹了仿QQ空間標(biāo)題欄漸變的實(shí)現(xiàn)方法的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-05-05
Android實(shí)現(xiàn)app分享文件到微信功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)app分享文件到微信功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05
詳解android 用webview加載網(wǎng)頁(https和http)
這篇文章主要介紹了詳解android 用webview加載網(wǎng)頁(https和http),詳細(xì)的介紹了兩個(gè)錯(cuò)誤的解決方法,有興趣的可以了解一下2017-11-11
Android編程實(shí)現(xiàn)的一鍵鎖屏程序詳解
這篇文章主要介紹了Android編程實(shí)現(xiàn)的一鍵鎖屏程序,結(jié)合實(shí)例形式詳細(xì)分析了Android一鍵鎖屏的原理與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-10-10
Flutter 設(shè)置全局字體的實(shí)現(xiàn)
本文主要介紹了Flutter 設(shè)置全局字體的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02

