也是一个布局容器,只有一个子组件,类似scrollView
public class MainActivity extends AppCompatActivity {
SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\_main);
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeLayout);
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent,
R.color.colorPrimary,
R.color.colorPrimary,
R.color.colorPrimaryDark);
swipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT);;
swipeRefreshLayout.setProgressViewOffset(true, 0, 200);
swipeRefreshLayout.setProgressViewEndTarget(true, 100);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Thread(new Runnable() {
@Override
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(1);
}
}).start();
}
});}
//handler
@SuppressLint("HandlerLeak")
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
Toast.makeText(MainActivity.this, "刷新成功", Toast.LENGTH\_SHORT).show();
swipeRefreshLayout.setRefreshing(false);
break;
}
}
};
}
属性一运行便知道,在监听器里执行刷新任务,用handler通知主线程
手机扫一扫
移动阅读更方便
你可能感兴趣的文章