Android也将下拉刷新这个常用的方式写入自带的控件库了,android.support.v4.widget.SwipeRefreshLayout,刷新状态通过SwipeRefreshLayout.OnRefreshListener来监听,实例:
package me.waye.d;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.support.v4.widget.SwipeRefreshLayout;import android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {    Button btn;    SwipeRefreshLayout swipeRefreshLayout;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);        btn = (Button) findViewById(R.id.btn);        btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                // Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.flip_in);                // Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.flip_out);//                Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.transition_out);//                swipeRefreshLayout.startAnimation(animation);                 startActivity(new Intent(MainActivity.this, SecondActivity.class));                 MainActivity.this.overridePendingTransition(R.anim.transition_in, R.anim.transition_out);            }        });        swipeRefreshLayout.setOnRefreshListener(this);        swipeRefreshLayout.setColorScheme(android.R.color.holo_blue_dark, android.R.color.holo_green_light, android.R.color.holo_orange_dark,                android.R.color.holo_red_dark);    }    @Override    public void onRefresh() {        try {            Thread.sleep(3000);            swipeRefreshLayout.setRefreshing(false);            Toast.makeText(MainActivity.this, "done", Toast.LENGTH_LONG).show();        } catch (InterruptedException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }}

更多相关文章

  1. ch02 Android(安卓)TextView与EditView
  2. 禁止Android的StatusBar下拉
  3. [Android]手动触发OnClick事件
  4. LocationManager Android自动定位使用以及注意事项(个人)
  5. android GPS 获取位置
  6. Android入门之SeekBar
  7. 【Android】_SmsReceicer_短信监听
  8. Android(安卓)底层渲染 - 屏幕刷新机制源码分析
  9. 获取Android设备电池电量状态

随机推荐

  1. Android(安卓)viewPage notifyDataSetCha
  2. android:网路检测
  3. android 傻瓜式 MultiDex 插件,从此再也不
  4. 一个android参考网站,工具+源码
  5. minSdkVersion各个版本号对应android版本
  6. android源码下载-等待提示动画
  7. centos下安装adb环境
  8. android:inputType参数类型说明
  9. Android通过PHP连接MySQL(传值查询)
  10. 【android】两个按钮的宽度各占屏幕的一