1.android6.0总结pullTorefresh 新控件SwipeRefreshLayout ,下拉刷新棒棒滴
首先是XML
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/id_swipe_ly"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/white"
android:listSelector="@color/text_f6"
android:numColumns="2"
android:stretchMode="columnWidth" >
</GridView>
</android.support.v4.widget.SwipeRefreshLayout>
2.Actitvity
public class BrandShowActivity extends AppBaseHeaderActivity implements SwipeRefreshLayout.OnRefreshListener {
@ViewInject(R.id.gridView)
GridView gridView;
@ViewInject(R.id.id_swipe_ly)
SwipeRefreshLayout mSwipeLayout;
private ItemAdapter itemAdapter;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.brandshow);
ViewUtils.inject(this);
initTopBarForLeft("品牌show");
itemAdapter = new ItemAdapter(this);
getItemData();
mSwipeLayout.setOnRefreshListener(this);
}
public void getItemData() {
List<Item> ctrList = new ArrayList<Item>();
ctrList.add(new Item(1, R.drawable.home_item_1, "安远网商"));
ctrList.add(new Item(2, R.drawable.home_item_2, "乐购安远"));
ctrList.add(new Item(3, R.drawable.home_item_3, "物流中心"));
ctrList.add(new Item(4, R.drawable.home_item_4, "产品溯源"));
ctrList.add(new Item(5, R.drawable.home_item_5, "电商学院"));
ctrList.add(new Item(6, R.drawable.home_item_6, "便民服务"));
ctrList.add(new Item(7, R.drawable.home_item_6, "便民服务"));
ctrList.add(new Item(8, R.drawable.home_item_6, "便民服务"));
itemAdapter.setData(ctrList);
gridView.setAdapter(itemAdapter);
}
@Override
public void onRefresh() {
mHandler.sendEmptyMessageDelayed(1, 1000);
}
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 1:
getItemData();
mSwipeLayout.setRefreshing(false);
break;
}
}
};
}
3.下拉效果棒棒滴还能改变颜色,不只是设置一种颜色,个人感觉比较炫
//, android.R.color.holo_purple, android.R.color.holo_orange_light, android.R.color.holo_red_light
mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright);