最近简单的使用了Android的下拉刷新控件SwipeRefreshLayout
首先是布局
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/id_listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
在activity中使用
private SwipeRefreshLayout mSwipeLayout; //下拉刷新控件
mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly);
mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.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);
刷新回调函数
@Override
public void onRefresh() {
// TODO Auto-generated method stub
//dosomething
mSwipeLayout.setRefreshing(false);
}
本文介绍了如何在Android应用中使用SwipeRefreshLayout实现下拉刷新功能。包括布局文件的配置及Activity中的初始化过程,还展示了如何设置刷新颜色方案以及监听刷新事件。
1万+

被折叠的 条评论
为什么被折叠?



