前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android学习---下拉刷新组建

android学习---下拉刷新组建

作者头像
yuanyuan
发布2019-09-10 18:00:26
1.3K0
发布2019-09-10 18:00:26
举报
文章被收录于专栏:小满小满

Google官方的下拉刷新组建

activity代码实现:

/** * The SwipeRefreshLayout should be used whenever the user * can refresh the contents of a view via a vertical swipe gesture. * */ public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout swipeLayout;

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); //Classes that wish to be notified when the swipe gesture correctly //triggers a refresh should implement this interface. swipeLayout.setOnRefreshListener(this); swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); }

/** * SwipeRefreshLayout.OnRefreshListener:Classes that wish to be notified when the swipe * gesture correctly triggers a refresh should implement this interface. * And trigger this function; */ @Override public void onRefresh() {

new Handler().postDelayed(new Runnable() { @Override public void run() { //Notify the widget that refresh state has changed. swipeLayout.setRefreshing(false); } }, 3000); }

}

xml实现activity_main.xml:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent" >

<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" >

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:gravity="center" android:text="@string/hello_world" /> </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-06-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档