1 回答

TA貢獻1890條經驗 獲得超9個贊
只要用戶可以通過垂直滑動手勢刷新視圖的SwipeRefreshLayout內容,就應該使用 。閱讀更多
所以,SwipeRefreshLayout它的行為就像一個容器,所以SwipeRefreshLayout你應該在里面添加一個ListVieworGridView來讓它工作,如下所示:
請記住,SwipeRefreshLayout只支持一個ListView或一個GridView孩子。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
然后,設置您的視圖元素:
SwipeRefreshLayout swipeRefreshLayout;
ListView listView;
protected override void OnCreate(Bundle savedInstanceState)
{
// ...
listView = view.FindViewById<ListView>(Resource.Id.list);
swipeRefreshLayout = view.FindViewById<SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
// Elevation helps users understand the relative importance of each element and focus their attention to the task at hand. (Optional)
// swipeRefreshLayout.Elevation = 10;
swipeRefreshLayout.Refresh += delegate (object sender, System.EventArgs e)
{
// logic...
};
// ...
}
此外,您可以通過以下方式手動觸發SwipeRefreshLayout:
swipeRefreshLayout.Post(() => {
swipeRefreshLayout.Refreshing = true;
listView.Clickable = false;
});
// logic...
swipeRefreshLayout.Post(() => {
swipeRefreshLayout.Refreshing = false;
listView.Clickable = true;
});
我希望這可以幫助你。
- 1 回答
- 0 關注
- 205 瀏覽
添加回答
舉報