PullToRefreshView下拉刷新上来加载更多,支持任何子view!
来源:互联网 发布:3d下期和值最简单算法 编辑:程序博客网 时间:2024/05/18 00:56
最新自己写了一个PullToRefreshView,这是一个自定义view,继承于LinearLayout,子控件可以是任意控件!先上一张福利图:
由于PullToRefreshView继承于LinearLayout,它有着ViewGroup的特性,子控件可以是任意的View。所以用法也和LinearLayout一样,我们来看一下xml中的布局:
<span style="font-size:14px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/dark_gray" android:orientation="vertical" ><com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView android:id="@+id/pull_to_refresh_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str01" android:textSize="14pt"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic01" android:contentDescription="@string/image_description"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic02" android:contentDescription="@string/image_description"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str02" android:textSize="14pt"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic03" android:contentDescription="@string/image_description"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic04" android:contentDescription="@string/image_description"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str03" android:textSize="14pt"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic05" android:contentDescription="@string/image_description"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pic06" android:contentDescription="@string/image_description"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str04" android:textSize="14pt"/> </com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView></LinearLayout></span>
其中com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView 就是自定一个的PullToRefreshView,用法和LinearLayout一致。
而Activity中的代码页很简单,如下:
<span style="font-size:14px;">package com.jimstin.pulltorefreshviewdemo;import com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView;import com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView.OnLoadListener;import com.jimstin.pulltorefreshviewdemo.view.PullToRefreshView.OnRefreshListener;import android.os.AsyncTask;import android.os.Bundle;import android.app.Activity;public class MainActivity extends Activity {private PullToRefreshView mPullToRefreshView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); }private void initView() {mPullToRefreshView = (PullToRefreshView) findViewById(R.id.pull_to_refresh_view);//这个方法必须要调用initLayoutParams()mPullToRefreshView.initLayoutParams();mPullToRefreshView.setOnRefreshListener(new OnRefreshListener() {@Overridepublic void onRefresh() {super.onRefresh();//模拟刷新new AsyncTask<Integer, Integer, Integer>() {@Overrideprotected Integer doInBackground(Integer... params) {try {//睡眠2秒Thread.sleep(2000);} catch (Exception e) {e.printStackTrace();}return null;}protected void onPostExecute(Integer result) {stopRefresh();};}.execute();}});mPullToRefreshView.setOnLoadListener(new OnLoadListener() {@Overridepublic void onLoad() {//模拟加载更多new AsyncTask<Integer, Integer, Integer>() {@Overrideprotected Integer doInBackground(Integer... params) {try {//睡眠2秒Thread.sleep(2000);} catch (Exception e) {e.printStackTrace();}return null;}protected void onPostExecute(Integer result) {stopLoad();};}.execute();super.onLoad();}});} }</span>
用法:
1.要调用PullToRefreshView.initLayoutParams()方法,初始化LayoutParams;
2.设置OnRefreshListener刷新监听器,当下拉松开手的时候,就会调用OnRefresh方法,调用完OnRefresh方法后,也就是刷新完毕后,记住调用stopRefresh()方法,用于停止刷新
3.设置OnLoadListener加载监听器,当上拉松开手的时候,就会调用OnLoad 方法,调用完OnLoad方法后,也就是加载更多完毕支护,记住要调用stopLoad()方法,用于停止加载
注意:目前的版本PullToRefreshView的父控件只能是LinearLayout
这个版本的PullToRefreshView写的还有待提高,不过这个版本也可以使用。
如大家在使用过程中遇到问题,欢迎留言!我会和大家一起解决。
源码地址:http://download.csdn.net/detail/zhangjm_123/8276943
0 0
- PullToRefreshView下拉刷新上来加载更多,支持任何子view!
- 《android》下拉刷新上拉加载更多控件 PullToRefreshView
- 将上拉加载更多下拉刷新PullToRefreshView用到项目中去
- 支持任意View下拉刷新/下拉加载更多的控件
- View下拉刷新加载更多
- 针对自定义组件上拉刷新下拉加载更多PullToRefreshView的分析(一)
- 针对自定义组件上拉刷新下拉加载更多PullToRefreshView的分析(二)
- 针对自定义组件上拉刷新下拉加载更多PullToRefreshView的分析(一)
- pullToRefreshView下拉刷新上拉加载
- pullToRefreshView下拉刷新上拉加载,pullrefreshlistview
- 下拉刷新--加载更多
- Android各种View的下拉刷新与加载更多
- RefreshView下拉刷新、上拉加载更多(支持ListView) ...
- Android_支持下拉刷新和加载更多的ExpandableListView
- XListView(下拉刷新上来加载)
- Android 下拉刷新加载更多
- ListView 下拉刷新 加载更多
- 下拉刷新与加载更多
- 绘制六面体
- framebuffer的结构介绍和驱动分析
- 深入理解C语言指针的奥秘
- c语言静态变量和静态函数
- windows环境下wampserver环境搭建
- PullToRefreshView下拉刷新上来加载更多,支持任何子view!
- 非线性最优化(二)——高斯牛顿法和Levengerg-Marquardt迭代
- Cython基础--Cython入门
- 简明 Vim 练级攻略(by陈皓)
- MFC 会员管理的一些笔记
- ORACLE解决锁表问题
- 可重入函数与不可重入函数
- 同步复位与异步复位
- uC/OS-II时间控制块1