SwipeRefreshLayout
public class SwipeRefreshLayout
extends ViewGroup implements NestedScrollingParent, NestedScrollingChild
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
public class SwipeRefreshLayout
extends ViewGroup implements NestedScrollingParent, NestedScrollingChild
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.support.v4.widget.SwipeRefreshLayout
API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
主要方法
-
setOnRefreshListener(OnRefreshListener): 为布局添加一个Listener
-
setRefreshing(boolean): 显示或隐藏刷新进度条
-
isRefreshing(): 检查是否处于刷新状态
-
setColorScheme(): 设置进度条的颜色主题,最多能设置四种
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/swipe_refresh_layout"><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:id="@+id/refresh"android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_gravity="center"android:textSize="24sp"android:text="下拉刷新" /></ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
在代码中使用:
public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);final TextView mTextView = (TextView)findViewById(R.id.refresh);final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_refresh_layout);mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_orange_light);mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener(){@Overridepublic void onRefresh() {mTextView.setText("正在刷新");// TODO Auto-generated method stub//boolean android.os.Handler.postDelayed(Runnable r, long delayMillis)new Handler().postDelayed(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubmTextView.setText("刷新完成");mSwipeRefreshLayout.setRefreshing(false);}}, 5000);}});}}
Tanks to:stormzhang:http://stormzhang.com/android/2014/03/29/android-swiperefreshlayout/
http://www.cnblogs.com/JinyaoLi/p/3852424.html