SwipeRefreshLayout的使用方法
来源:互联网 发布:英雄联盟单机版mac 编辑:程序博客网 时间:2024/06/05 17:54
SwipeRefreshLayout其实是一个viewgroup,它其中只能含有一个子view.用法很简单,
activity_main.xml:
<?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 xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/swipeLayout" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="wrap_content"/> </android.support.v4.widget.SwipeRefreshLayout></LinearLayout>item.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/item_tv" android:layout_width="match_parent" android:layout_height="60dp" android:text="TO BE BETTER!" android:textSize="18dp" android:gravity="center" android:background="#cde78a" /></RelativeLayout>MainActivity:public class MainActivity extends AppCompatActivity { ListView listview; List<String> list; SwipeRefreshLayout srfl; MyAdapter adapter; Handler h; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); h=new Handler(){ @Override public void handleMessage(Message message) { adapter.notifyDataSetChanged(); srfl.setRefreshing(false); } }; srfl = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);//设置swiperefreshlayout refresh(); listview = (ListView) findViewById(R.id.listview); //初始化listview数据list=new ArrayList<String>(); for (int i=0;i<30;i++) { list.add("BETTER "+i); } adapter = new MyAdapter(list); listview.setAdapter(adapter); } //listView的adapter class MyAdapter extends BaseAdapter{ List<String> list; public MyAdapter(List<String> list) { this.list=list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Holder h; if (convertView == null) { convertView = MainActivity.this.getLayoutInflater().inflate(R.layout.item, null); h = new Holder(); h.tv = (TextView) convertView.findViewById(R.id.item_tv); convertView.setTag(h); } else { h=(Holder)convertView.getTag(); } if (position % 6 == 0) { h.tv.setBackgroundColor(Color.parseColor("#78aced")); } else { h.tv.setBackgroundColor(Color.parseColor("#cde78a")); } h.tv.setText(list.get(position)); return convertView; } class Holder{ public TextView tv; } } public void refresh(){// 设置小球弹回后的位置// srfl.setProgressViewEndTarget(true, 180);// 设置小球开始和结束的位置// srfl.setProgressViewOffset(true,400,500);// 设置圆球的大小 只有两种// srfl.setSize(SwipeRefreshLayout.LARGE);// 小圆球的背景色和渐变border色// srfl.setProgressBackgroundColorSchemeColor(Color.parseColor("#ffffff"));// 设置旋转箭头的颜色 方法1// srfl.setColorSchemeResources(R.color.swipe1,// R.color.swipe2,// R.color.swipe3,// R.color.swipe4); //设置旋转箭头的颜色 方法2 srfl.setColorSchemeColors( R.color.swipe2, R.color.swipe3, R.color.swipe4);// 设置手势滑动的距离和小圆球下降的距离比例,数值越大,手指就需要向下滑动越长得距离唤出小球// srfl.setDistanceToTriggerSync(300);//设置监听的刷新事件,需要开一个线程,不然会导致UI界面小球的旋转卡住 srfl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Thread(new Runnable() { @Override public void run() { for (int i=0;i<5;i++) { list.add(0,"NEW "+i); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } h.sendMessage(new Message()); onRefreshing=true; } }).start(); } }); }}主要用法如上面代码的注释。如有不对的地方,感谢指出。
0 0
- SwipeRefreshLayout的使用方法
- 安卓SwipeRefreshLayout的使用方法
- SwipeRefreshLayout基本使用方法
- android的SwipeRefreshLayout 扩展
- Android官方的SwipeRefreshLayout
- Android官方的SwipeRefreshLayout
- CoordinatorLayout、SwipeRefreshLayout的使用
- SwipeRefreshLayout的简单使用
- SwipeRefreshLayout 的简单使用
- Android SwipeRefreshLayout的使用
- SwipeRefreshLayout 的基本使用
- SwipeRefreshLayout的事件处理
- SwipeRefreshLayout的样式
- SwipeRefreshLayout的用法
- SwipeRefreshLayout的使用注意事项
- 简单的使用SwipeRefreshLayout
- SwipeRefreshLayout的使用详解
- SwipeRefreshLayout的简单使用
- Java通过Jnative调用windows API接口学习总结
- Android自定义View-Matrix详解
- Android硬件加速以及【WebView】的onPause,onResume,OnDestroy
- Javascript—事件冒泡和事件捕获
- 代码笔记 | UDP编程实现
- SwipeRefreshLayout的使用方法
- leetcode:sort:Wiggle Sort II(324)
- 设备驱动的probe、remove以及shutdown的顺序
- easyui增删改查全部代码
- 腾讯高级工程师:一道面试题引发的高并发性能调试思考
- Jquery中的(function($){...})(jQuery)
- android studio 去除APP的应用标题栏
- Bootstrap Form两列布局
- 激活函数-Concatenated Rectified Linear Units