欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-17 17:53:10
swiperefreshlayout实现下拉小球式的刷新,供大家参考,具体内容如下 布局文件:

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);
 }
}

效果图:

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

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

上一篇:

下一篇: