如何拦截mini-mvcpagerr

26861人阅读
android(39)
Android listview viewpager滑动 跳动&冲突解决&
ListView中嵌套ViewPage有或者滑动手势冲突解决
在listview 上使用&addHeaderView 在第一栏添加&viewpager 当做header&
当触发 滑动事件 的时候容易引起 滑动冲突 & &(比如斜着滑动viewpager &的时候 listview会跳动)
特别是在 &下拉刷新或者上拉加载 的时候 , 组件可能会传递到viewpager当中
查阅了很多的帖子 &发现修改起来都非常麻烦&
(1)解决方案
1. 针对viewpager 做了些修改 &
替换掉support.v4当中的viewpager即可:
package com.example.bz_
import android.content.C
import android.support.v4.view.ViewP
import android.util.AttributeS
import android.view.MotionE
import android.view.ViewG
* viewpage 和listview 相互冲突 将父view 传递到viewpage 里面
* 使用父类的方法 parent.requestDisallowInterceptTouchEvent(true);
* 当 requestDisallowInterceptTouchEvent 如果为true的时候 表示:父view 不拦截子view的touch 事件
* 这个方法只是改变flag
* @author baozi
public class DecoratorViewPager extends ViewPager {
private ViewG
public DecoratorViewPager(Context context) {
super(context);
// TODO Auto-generated constructor stub
public DecoratorViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
public void setNestedpParent(ViewGroup parent) {
this.parent =
public boolean dispatchTouchEvent(MotionEvent ev) {
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
return super.onInterceptTouchEvent(arg0);
public boolean onTouchEvent(MotionEvent arg0) {
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(arg0);
2 . 在xml里面:
&?xml version=&1.0& encoding=&utf-8&?&
&RelativeLayout xmlns:android=&/apk/res/android&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent&
android:background=&#f1f1f1& &
&com.example.bz_viewpager.DecoratorViewPager
android:id=&@+id/vp&
android:layout_width=&match_parent&
android:layout_height=&200dp&
android:fadingEdge=&none& /&
&/RelativeLayout&
3. 在代码里使用
将 viewpager 的父view传递到viewpager里面 &
调用: & & & vp.setNestedpParent((ViewGroup)vp.getParent()); 方法
lv = (ListView) findViewById(R.id.lv);
View header = LayoutInflater.from(MainActivity.this).inflate(R.layout.viewpage_layout, null);
DecoratorViewPager vp = (DecoratorViewPager) header.findViewById(R.id.vp);
vp.setNestedpParent((ViewGroup)vp.getParent());
MyPagapter myPagapter = new MyPagapter(MainActivity.this);
vp.setAdapter(myPagapter);
lv.addHeaderView(header);
viewgroup 当中有 一个&requestDisallowInterceptTouchEvent方法
这个方法只改变flag &当 view.requestDisallowInterceptTouchEvent 参数为true的时候 &
view 不会拦截其子控件的 触摸事件
* Called when a child does not want this parent and its ancestors to
* intercept touch events with
* {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
* &p&This parent should pass this call onto its parents. This parent must obey
* this request for the duration of the touch (that is, only clear the flag
* after this parent has received an up or a cancel.&/p&
* @param disallowIntercept True if the child does not want the parent to
intercept touch events.
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
if (disallowIntercept == ((mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0)) {
// We're already in this state, assume our ancestors are too
if (disallowIntercept) {
mGroupFlags |= FLAG_DISALLOW_INTERCEPT;
mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT;
// Pass it up to our parent
if (mParent != null) {
mParent.requestDisallowInterceptTouchEvent(disallowIntercept);
Demo 下载地址:
http://download.csdn.net/detail/aaawqqq/8447693
祝福大家每日精进
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:927656次
积分:7339
积分:7339
排名:第2418名
原创:93篇
评论:312条
文章:22篇
阅读:312632
(2)(2)(2)(3)(2)(1)(1)(5)(2)(4)(3)(3)(1)(5)(11)(3)(23)(5)(2)(6)(10)(2)(1)jQuery MiniUI 开发教程 导航控件 Pager:分页控件(十)
& & & & & &&
& & & & &&& & & & & &
参考示例:Pager:分页控件
& & & & & &&
& & & & & &
创建代码 &&
&div class=&mini-pager& style=&width:600background:#&&
& & totalCount=&123& onpagechanged=&onPageChanged& sizeList=&[5,10,20,100]&
& & showTotalCount=&true&
& & & & & & &
&/div& & &
&script type=&text/javascript&&
& & function onPageChanged(e) {
& & & & alert(e.pageIndex+&:&+e.pageSize);
& & } & & &&
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'}

我要回帖

更多关于 如何刷新pager 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信