国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android SwipeRefreshLayout下拉刷新源碼解析

2019-12-12 04:47:05
字體:
來源:轉載
供稿:網友

本文實例為大家分享了SwipeRefreshLayout下拉刷新源碼,供大家參考,具體內容如下

1.SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一個下拉刷新組件,實現刷新效果更方便。

弊端:只有下拉

//設置刷新控件圈圈的顏色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);//設置刷新控件背景色swipe_refresh_layout.setProgressBackgroundColorSchemeColor(getResources().getColor(android.R.color.white));//設置滑動距離swipe_refresh_layout.setDistanceToTriggerSync(100);//設置大小模式swipe_refresh_layout.setSize(SwipeRefreshLayout.DEFAULT);//設置下拉刷新控件狀態隱藏swipe_refresh_layout.setRefreshing(false);  

2.在xml文件中引用android.support.v4.widget.SwipeRefreshLayout控件,在里面可以放置任何一個控件,例如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); }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 华坪县| 缙云县| 时尚| 湘乡市| 望都县| 蕲春县| 岑巩县| 建水县| 观塘区| 金华市| 洛隆县| 石棉县| 莱州市| 太仓市| 客服| 德阳市| 桐城市| 涞水县| 台山市| 常州市| 万宁市| 油尖旺区| 亳州市| 宁武县| 庆元县| 云和县| 杨浦区| 太原市| 镶黄旗| 秦安县| 天门市| 永济市| 红河县| 界首市| 沙雅县| 舒兰市| 太和县| 普兰店市| 无为县| 永和县| 壤塘县|