最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android SwipeRefreshLayout下拉刷新源碼解析

 更新時(shí)間:2016年11月06日 09:41:15   作者:ganchuanpu  
這篇文章主要為大家詳細(xì)解析了Android SwipeRefreshLayout下拉刷新源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

资溪县| 南澳县| 合肥市| 丁青县| 垣曲县| 朔州市| 霸州市| 九台市| 阿尔山市| 宁津县| 勃利县| 广昌县| 乌拉特中旗| 和平县| 石台县| 永宁县| 庄河市| 内乡县| 丰台区| 冕宁县| 湟源县| 防城港市| 高淳县| 织金县| 大城县| 慈溪市| 新化县| 万源市| 蒙自县| 文化| 洪泽县| 汪清县| 鄂尔多斯市| 湛江市| 澄迈县| 涪陵区| 湘阴县| 四平市| 花莲县| 抚州市| 河北省|