转载请注明出处:http://blog.csdn.net/itachi85/article/details/41246039
下载第三方控件和所需的资源
ActionBar-PullToRefresh:https://github.com/chrisbanes/ActionBar-PullToRefresh
SmoothProgressBar:https://github.com/castorflex/SmoothProgressBar
导入SmoothProgressBar
下面有两个文件夹 java 和 res,java里面有一个fr文件夹扔到你的项目里,res里面有两个value的文件夹,把里面的xml文件稍微改下名字扔到项目中。
在这里我把包名改了,前面加上了com
导入ActionBar-PullToRefresh
目录下面有4个文件,将extras,library的java文件夹中的内容扔进项目里,res中的xml改下名字扔到项目中。
在这里我把包名改了,前面加上了com
使用控件
参考samples下面的ListViewActivity:\ActionBar-PullToRefresh-master\ActionBar-PullToRefresh-master\samples\actionbarcompat\src\java\uk\co\senab\actionbarpulltorefresh\samples\actionbarcompat
我的使用:
private void initRefreshview(View view) {
ViewGroup viewGroup = (ViewGroup) view;
mPullToRefreshLayout = new PullToRefreshLayout(viewGroup.getContext());
ActionBarPullToRefresh
.from(getActivity())
// We need to insert the PullToRefreshLayout into the Fragment's
// ViewGroup
.insertLayoutInto(viewGroup)
// Here we mark just the ListView and it's Empty View as
// pullable
.theseChildrenArePullable(R.id.lv_dynamic, android.R.id.empty)
.listener(this).setup(mPullToRefreshLayout);
}
把initRefreshow()方法放入oncreat()或者onViewCreated()方法中就行,改变你需要监听滑动的区域,我这里是R.id.lv_list和android.R.id.emptyf\分别代表listview和界面空白。