Xamarin android SwipeRefreshLayout入门实例
来源:互联网 发布:星际淘宝网精校 编辑:程序博客网 时间:2024/04/29 06:50
android SwipeRefreshLayout 是实现的效果就是上滑下拉刷新ListView 获取其他控件数据.基本上每个App都有这种效果。Google提供了一个官方的刷新控件SwipeRefreshLayout,当然你得引入V4兼容包哦还不错项目中也用到了。所以就演示一下这个控件怎么使用吧.
还是先看一下Android SwipeRefreshLayout的API吧
谷歌翻译是这么说的:
的SwipeRefreshLayout应该用于每当用户可以通过一个垂直扫掠姿态刷新的图的内容。每当完成刷新姿态刷卡被告知实例这种观点应该添加一个OnRefreshListener的活动。该SwipeRefreshLayout将通知每一个手势再次完成一次每个听者和; 听者负责正确确定何时开始实际内容的刷新。如果侦听确定不应该有一个刷新,它必须调用setRefreshing(假)来取消刷新的任何可视指示。如果活动希望只显示进度动画,它应该调用setRefreshing(真)。要禁用的姿态和进步的动画,在视图上调用的setEnabled(假)。
这种布局应该由将被刷新为手势的结果,只能支持一个直接子视图的父。此视图也将作出手势的目标和将被迫以匹配的宽度,并在此布局提供的高度。该SwipeRefreshLayout不提供无障碍的事件; 相反,必须提供一个菜单项,以允许内容的刷新无论使用该手势。
看一下 效果图:
具体代码如下,先看一下布局页:Main.axml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </android.support.v4.widget.SwipeRefreshLayout></LinearLayout>MainActivity.cs:
using Android.App;using Android.Runtime;using Android.Widget;using Android.OS;using Android.Support.V4.Widget;namespace SwipeRefreshLayoutDemo{ [Activity(Label = "SwipeRefreshLayoutDemo", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { int count = 1; private SwipeRefreshLayout swipeRefreshLayout; private ListView listView; private ArrayAdapter<string> adapter; private JavaList<string> data= new JavaList<string>{"恩比德","拉塞尔","安东尼-戴维斯","西蒙斯"}; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); listView = (ListView)FindViewById(Resource.Id.listView); swipeRefreshLayout = FindViewById<SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.Refresh += (s, e) => { data.Add("张林-布莱恩特"); adapter.NotifyDataSetChanged(); swipeRefreshLayout.SetColorScheme(Android.Resource.Color.HoloRedLight); swipeRefreshLayout.Refreshing=false; }; adapter = new ArrayAdapter<string>(this,Android.Resource.Layout.SimpleListItem1,data); listView.Adapter = adapter; } }}
示例非常简单,体验一下效果而已。也许有人很郁闷了,这个JavaList是什么玩意?如果用List的话,下拉刷新就没有效果。目前就到这儿,过两天去问问牛哥,看是怎么回事。
昨天晚上写的,今天下午来改一改。终于找到了原因,这个Android自带的适配器选项样式对于List可能是个bug,所以呢自己写一个Adapter就可以用List了
示例代码下载:http://download.csdn.net/detail/kebi007/9652257作者:张林
原文地址:http://blog.csdn.net/kebi007/article/details/52801731
转载随意注明出处
- Xamarin android SwipeRefreshLayout入门实例
- Xamarin.Android 入门开发
- Xamarin.Android快速入门
- Xamarin.Android入门
- 【Xamarin.Android】 Async / Await入门
- Xamarin.Android 入门之:Xamarin+vs2015 环境搭建
- Xamarin.Android 入门之:Xamarin+vs2015 环境搭建
- Xamarin android 使用RecyclerView结合SwipeRefreshLayout下拉刷新滑到底部加载更多
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Android SwipeRefreshLayout
- Xamarin.Android开发入门——Hello,Android深入理解
- Android零基础入门第72节:SwipeRefreshLayout下拉刷新
- 第一个Python demo
- POJ 1185 炮兵阵地 (状压DP || 最大团算法)
- Web前端面试指导(四十一):html5有哪些新特性、移除了那些元素?
- Redis入门之浅谈aof持久化机制
- BZOJ 2038 [2009国家集训队]小Z的袜子(hose)
- Xamarin android SwipeRefreshLayout入门实例
- uva129困难的串(dfs+判断)
- mysql进入某个数据库
- Eclipse将项目上传到码云(git.oschina)
- 电脑上所有浏览器都不能上网但是qq可以登陆上
- Mac下jdk+maven+tomacat配置
- handler 主线程与子线程之间的通信
- Charles4.0.1使用更新
- BZOJ 2821 作诗(Poetize)