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. listview更改选中时item背景色的两种方式
  2. Android多屏幕适配
  3. Android 属性动画Property Animation(下)
  4. android log机制——输出log
  5. android霓虹灯源代码——基础编
  6. Android系统各种类型的service刨根解读
  7. Android 使用弹出对话框,报Unable to add
  8. Android重力感应 .
  9. Android WebView+JSON+JavaScript
  10. 【转】Android状态栏、导航栏、DecorView