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. 关于屏幕解锁的实例
  2. android之AutoCompleteTextView控件用法
  3. Android SDK 实例代码分析---Accelerometer Play(二)
  4. 控件属性:
  5. Android:控件GridView的使用实例
  6. 系出名门Android(5) - 控件(View)
  7. Android UI开发第十七篇——Android Fragment实例
  8. android基础入门控件详解(3)

随机推荐

  1. 为Android开发环境安装BlackBerry PlayBo
  2. Android之NDK开发
  3. android switch模块
  4. android - 为响应度而设计 - 开发文档翻
  5. Android的Activity屏幕切换动画(一)-左右
  6. Android(安卓)Studio快捷键大全
  7. Android(安卓)ICS关机跟重新启动功能研究
  8. Android下修改hosts文件
  9. Android(安卓)高手进阶教程(十四)之----A
  10. Android(安卓)启动过程详解