当前位置: 移动技术网 > 移动技术>移动开发>Android > android组件SwipeRefreshLayout下拉小球式刷新效果

android组件SwipeRefreshLayout下拉小球式刷新效果

2019年07月24日  | 移动技术网移动技术  | 我要评论

swiperefreshlayout实现下拉小球式的刷新,供大家参考,具体内容如下

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingleft="@dimen/activity_horizontal_margin"
android:paddingright="@dimen/activity_horizontal_margin"
android:paddingtop="@dimen/activity_vertical_margin"
android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity">

  <android.support.v4.widget.swiperefreshlayout
    android:id="@+id/swiperefreshlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  >
   <listview
     android:id="@+id/listview"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
   </listview>
  </android.support.v4.widget.swiperefreshlayout>

</relativelayout>

mainactivity:

public class mainactivity extends appcompatactivity implements swiperefreshlayout.onrefreshlistener{

private static final int refresh_status =0;
private listview mylistview;
private swiperefreshlayout myswiperefreshlayout;
private arrayadapter<string> listadapter;
private list<string> listide = new arraylist<string>(arrays.aslist("visual studio", "android studio", "eclipse", "xcode"));
private handler refreshhandler = new handler()
{
  public void handlemessage(android.os.message msg)
  {
    switch (msg.what)
    {
      case refresh_status:
        listide.removeall(listide);
        listide.addall(arrays.aslist("c#", "java", "c++","object-c"));
        listadapter.notifydatasetchanged();
        myswiperefreshlayout.setrefreshing(false);
        break;

    }
  };
};
protected void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  setcontentview(r.layout.activity_main);
  mylistview = (listview) findviewbyid(r.id.listview);
  myswiperefreshlayout = (swiperefreshlayout) findviewbyid(r.id.swiperefreshlayout);

  myswiperefreshlayout.setonrefreshlistener(this);
  myswiperefreshlayout.setcolorschemeresources(android.r.color.holo_blue_bright, android.r.color.holo_green_light,
      android.r.color.holo_orange_light, android.r.color.holo_red_light);
  listadapter = new arrayadapter(this,android.r.layout.simple_list_item_1,listide);
  mylistview.setadapter(listadapter);
}

@override
public void onrefresh() {
  refreshhandler.sendemptymessagedelayed(refresh_status, 1500);
 }
}

效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网