<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > Android開(kāi)發(fā)之SwipeRefreshLayout實(shí)現下拉刷新

Android開(kāi)發(fā)之SwipeRefreshLayout實(shí)現下拉刷新

作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò ) 收藏

簡(jiǎn)介

本文引用地址:http://dyxdggzs.com/article/201609/303423.htm

SwipeRefreshLayout是Google官方推出的一款下拉刷新組件,位于v4兼容包下,android.support.v4.widget.SwipeRefreshLayout,Support Library 必須19.1以上。使用起來(lái)很簡(jiǎn)單,只要在需要刷新的控件最外層加上SwipeRefreshLayout,其child必須是可滾動(dòng)的view,如ScrollView、GridView或者ListView,這里就測試最常用的ListView。

布局

xmlns:tools=http://schemas.android.com/tools

android:layout_width=match_parent

android:layout_height=match_parent

android:paddingBottom=@dimen/activity_vertical_margin

android:paddingLeft=@dimen/activity_horizontal_margin

android:paddingRight=@dimen/activity_horizontal_margin

android:paddingTop=@dimen/activity_vertical_margin

tools:context=.MainActivity>

android:id=@+id/swipeLayout

android:layout_width=match_parent

android:layout_height=match_parent>

android:id=@+id/listview

android:layout_width=match_parent

android:layout_height=match_parent>

Activity

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

private SwipeRefreshLayout mSwipeLayout;

private ListView mListView;

private ArrayAdapter mAdapter;

private ArrayList data;

private boolean isRefresh = false;//是否刷新中

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

init();

//設置SwipeRefreshLayout

mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);

//設置進(jìn)度條的顏色主題,最多能設置四種 加載顏色是循環(huán)播放的,只要沒(méi)有完成刷新就會(huì )一直循環(huán),holo_blue_bright>holo_green_light>holo_orange_light>holo_red_light

// 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);

//上面的方法已經(jīng)廢棄

mSwipeLayout.setColorSchemeColors(Color.BLUE,

Color.GREEN,

Color.YELLOW,

Color.RED);

// 設置手指在屏幕下拉多少距離會(huì )觸發(fā)下拉刷新

mSwipeLayout.setDistanceToTriggerSync(300);

// 設定下拉圓圈的背景

mSwipeLayout.setProgressBackgroundColorSchemeColor(Color.WHITE);

// 設置圓圈的大小

mSwipeLayout.setSize(SwipeRefreshLayout.LARGE);

//設置下拉刷新的監聽(tīng)

mSwipeLayout.setOnRefreshListener(this);

}

/*

* 初始化 設置ListView

*/

private void init() {

mListView = (ListView) findViewById(R.id.listview);

data = new ArrayList();

for (int i = 1; i 10; i++) {

data.add(這是第 + i + 個(gè)數據);

}

//初始化adapter

mAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, data);

mListView.setAdapter(mAdapter);

}

/*

* 監聽(tīng)器SwipeRefreshLayout.OnRefreshListener中的方法,當下拉刷新后觸發(fā)

*/

public void onRefresh() {

//檢查是否處于刷新?tīng)顟B(tài)

if (!isRefresh) {

isRefresh = true;

//模擬加載網(wǎng)絡(luò )數據,這里設置4秒,正好能看到4色進(jìn)度條

new Handler().postDelayed(new Runnable() {

public void run() {

//顯示或隱藏刷新進(jìn)度條

mSwipeLayout.setRefreshing(false);

//修改adapter的數據

data.add(這是新添加的數據);

mAdapter.notifyDataSetChanged();

isRefresh = false;

}

}, 4000);

}

}

}

問(wèn)題

細心的讀者肯定發(fā)現,代碼中 setColorSchemeColors 設置顏色時(shí)候并未按如下設置

mSwipeLayout.setColorSchemeColors(android.R.color.holo_blue_bright,

android.R.color.holo_green_light,

android.R.color.holo_orange_light,

android.R.color.holo_red_light);

那是因為,經(jīng)過(guò)測試,如果按照如上設置顏色,進(jìn)度條不會(huì )有顏色循環(huán)的效果,不知道為何?難道是bug嗎?



關(guān)鍵詞: Android

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>