SwipeRefreshLayout官方推薦下拉刷新
SwipeRefreshLayout
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): 為布局添加一個(gè)Listener
setRefreshing(boolean): 顯示或隱藏刷新進(jìn)度條
isRefreshing(): 檢查是否處于刷新狀態(tài)
setColorScheme(): 設(shè)置進(jìn)度條的顏色主題,最多能設(shè)置四種
布局:在最外層加上SwipeRefreshLayout,他的child是可滾動(dòng)的view即可,如ScrollView或者ListView
在代碼中使用:
public?class?MainActivity?extends?ActionBarActivity?{ @Override protected?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(){ @Override ???????????????public?void?onRefresh()?{ ?? mTextView.setText("正在刷新"); ?????????????????//?TODO?Auto-generated?method?stub ?? //boolean?android.os.Handler.postDelayed(Runnable?r,?long?delayMillis) ??????????????????new?Handler().postDelayed(new?Runnable()?{ ????????????????????? ?????????????????????@Override ????????????????????public?void?run()?{ ?????????????????????????//?TODO?Auto-generated?method?stub ???????????????????? ?mTextView.setText("刷新完成"); ???????????????????? ?mSwipeRefreshLayout.setRefreshing(false); ?????????????????????} ?????????????????},?5000); ????????????} }); } }