[英]Swipe to Refresh Layout without ListView
我想刷新我的頁面,但我沒有listview
或recyclerview
之類的東西。 我想向下滑動以刷新片段。 還應該有動畫。 是否可以在沒有任何listview
的情況下使用滑動刷新模塊等等
感謝您的回復
是的,您也可以與LinearLayout、RelativeLayout一起使用。 有關更多詳細信息,請參見下面的代碼,
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// Other child views
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
謝謝。
是的,它不僅適用於 listview/recycler view 。 它可以包含滾動視圖或適配器視圖。 請參考此https://stackoverflow.com/a/10971722/4781390
盡管文檔在“添加 SwipeRefreshLayout 小部件”中說它只支持 ListView 和 GridView,但它也支持其他布局。
請記住 SwipeRefreshLayout 僅支持單個 ListView 或 GridView 子項。
在文檔的上一頁(概述)上,它鏈接到一個示例應用程序,該示例應用程序表明它實際上是受支持的:
該示例展示了如何使用 SwipeRefreshLayout 將“滑動刷新”手勢添加到具有多個子項的布局中,從而能夠通過在可見視圖上向下滑動來觸發刷新。 在此示例中,SwipeRefreshLayout 包含一個可滾動的 GridView,以及一個 TextView 空視圖。
所以我用constraintLayout試了一下,效果很好
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/myConstraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="80dp">
...
但是您必須手動將刷新狀態設置回false
swipeRefreshLayout.setOnRefreshListener {
Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout")
myUpdateOperation()
}
像這樣:
fun myUpdateOperation() {
...
swipeRefreshLayout.isRefreshing = false
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.