SwipeRefresh下拉刷新

SwipeRefreshLayout实质上是一个ViewGroup,所以将其作为根布局


<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.example.swiperefreshdemo.MainActivity">

 

<android.support.v4.widget.SwipeRefreshLayout

android:id="@+id/swipeLayout"

android:layout_width="match_parent"

android:layout_height="match_parent">

 

<ListView

android:id="@+id/listView"

android:layout_width="match_parent"

android:layout_height="match_parent">

</ListView>

 

</android.support.v4.widget.SwipeRefreshLayout>

 

</LinearLayout>

 

经过这个步骤,在页面上就已经能够下拉看到控件

 

public classMainActivity extends AppCompatActivity implementsSwipeRefreshLayout.OnRefreshListener{

private static final int REFRESH_COMPLETE=0x01;

private SwipeRefreshLayout refreshLayout;

 

private Handler handler=new Handler(){

public void handleMessage(android.os.Message msg){

switch(msg.what){

case REFRESH_COMPLETE:

refreshLayout.setRefreshng(false);

break;

}

}

};

 

@SuppressLint("ResourceAsColor")

@Override

protected void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

 

refreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipeLayout); 

refreshLayout.setColorSchemeColors(Color.BLUE,Color.GREEN,Color.RED);

refreshLayout.setSize(SwipeRefreshLayout.DEFAULT);

refreshLayout.setOnRefreshListener(this);

}

 

public void onRefresh(){

//执行操作的更新等操作

 

//刷新成功

handler.sendEmptyMessageDelayed(REFRESH_COMPLETE,2000);

}

}

 

SwipeRefreshLayout方法介绍

  1. setColorSchemeResources(int…args):设置刷新时圆圈的颜色变化,为int数组
  2. setSize(int size):设置刷新时圆圈的大小,有DEFAULT(小)和LARGE两个值,默认是DEFAULT
  3. setOnRefreshListener(OnRefreshListener):设置刷新时回调监听事件,刷新时调用
  4. setRefreshing(boolean refreshing):设置是否继续正在刷新
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值