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 关注
- 190 浏览
添加回答
举报