日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android下拉刷新SwipeRefreshLayout简单用法

發(fā)布時間:2023/12/20 Android 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android下拉刷新SwipeRefreshLayout简单用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

之前一直都想用下拉刷新,感覺上是龐大的工程,所以擱置了。現(xiàn)在學習了一下其實真的超級簡單。

看了《第一行代碼》以及 https://www.jianshu.com/p/3c402a9e4b7d文章

看上去是真的簡單。SwipeRefreshLayout下嵌套一個控件

1.布局代碼

<android.support.v4.widget.SwipeRefreshLayoutandroid:id="@+id/mswipeRefreshLayout"android:layout_width="match_parent"android:layout_height="match_parent" ><WebViewandroid:id="@+id/mwebview"android:layout_width="match_parent"android:layout_height="match_parent"></WebView> </android.support.v4.widget.SwipeRefreshLayout>

混編的app,這里嵌套了一個webview

2.Activity代碼

mSwipe = findViewById(R.id.mswipeRefreshLayout);private void setSwipe() {/** 設置下拉刷新球顏色*/mSwipe.setColorSchemeResources(R.color.swipeColor1,R.color.swipeColor2,R.color.swipeColor3,R.color.swipeColor4,R.color.swipeColor5);/** 設置下拉刷新的監(jiān)聽*/mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {@Overridepublic void onRefresh() {//刷新需執(zhí)行的操作}}); }

?我們可以在res/values/colors.xml文件中設置我們想要的顏色

<color name="swipeColor1">#3F51B5</color> <color name="swipeColor2">#000000</color> ......

加載完畢后需要關(guān)閉下拉刷新球

mSwipe.setRefreshing(false);

3.打開頁面自動刷新

mSwipe.measure(0,0);
mSwipe.setRefreshing(true);

在onMeasure之前 單獨使用setRefreshing(true)是沒有效果的

?

還可以復寫onWindowFocusChanged當頁面獲得焦點的時刷新

@Overridepublic void onWindowFocusChanged(boolean hasFocus) {super.onWindowFocusChanged(hasFocus);mSwipe.setRefreshing(true);}

?

也可以放到ui線程消息循環(huán)中排隊

mSwipe.post(new Runnable() {@Overridepublic void run() {mSwipe.setRefreshing(true);}});

?

在刷新結(jié)束后關(guān)閉刷新球

public void SwipeIsFinish(){if (mSwipe.isRefreshing()) {mSwipe.setRefreshing(false);}}

?

轉(zhuǎn)載于:https://www.cnblogs.com/Steffen-xuan/p/11196474.html

總結(jié)

以上是生活随笔為你收集整理的Android下拉刷新SwipeRefreshLayout简单用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。