Android下拉刷新控件
16lz
2021-12-04
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(); } }}
更多相关文章
- ch02 Android(安卓)TextView与EditView
- 禁止Android的StatusBar下拉
- [Android]手动触发OnClick事件
- LocationManager Android自动定位使用以及注意事项(个人)
- android GPS 获取位置
- Android入门之SeekBar
- 【Android】_SmsReceicer_短信监听
- Android(安卓)底层渲染 - 屏幕刷新机制源码分析
- 获取Android设备电池电量状态