捕获刷卡解雇的ListView手势ViewPager [英] Capture swipe to dismiss listview gestures in ViewPager
问题描述
我有一个的ListView
,抓住滑动手势删除行。这的ListView
生活在一个片段
。在手机上,这是在它自己的活动
和伟大工程。在平板电脑这个片段
是一个 ViewPager
和的ListView
是永远不能捕捉到任何的刷卡事件,因为他们经常去 ViewPager
。
我怎么会去确保滑动手势,由的ListView
被捕获消耗它们传递给 ViewPager 前code>?
P.S。
我使用这个库我刷卡解雇手势在我的的ListView
我将如何着手确保滑动手势的ListView控件被捕获消耗它们传递给ViewPager过吗?
创建 ViewPager
的子类,并覆盖 canScroll()
。如果提供的查看
是的ListView
,返回真
来已经触摸事件给予了的ListView
。
例如,这里是一类我一些样品中使用的主办地图一个 ViewPager
:
/ ***
版权所有(c)2013 CommonsWare,LLC
Apache许可证下授权,版本2.0(以下简称许可证);你不可以
使用本文件除了符合许可。你可以得到一个副本
许可在http://www.apache.org/licenses/LICENSE-2.0的。除非需要
适用法律或书面同意,在分布式软件
许可分布在原样的基础,没有担保或条件
任何形式的,无论是前preSS或暗示的保证。查看许可证的具体
语言的管理许可和限制的授权。
从用英语翻译忙codeR指南到Android Development_
http://commonsware.com/Android
* /
包com.commonsware.android.mapsv2.pager;
进口android.content.Context;
进口android.support.v4.view.PagerTabStrip;
进口android.support.v4.view.ViewPager;
进口android.util.AttributeSet;
进口android.view.SurfaceView;
进口android.view.View;
公共类MapAwarePager扩展ViewPager {
公共MapAwarePager(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}
@覆盖
保护布尔canScroll(视图V,布尔checkV,INT DX,INT X,
int y)对{
如果(V的instanceof SurfaceView || v的instanceof PagerTabStrip){
返回(真);
}
返回(super.canScroll(ⅴ,checkV,DX,X,Y));
}
}
现在,这是完全可能的,可能会有更多,让你的刷卡到解雇劳动 ViewPager
里面,但我会从这里开始。
I have a ListView
that captures swipe gestures to delete a row. This ListView
lives in a Fragment
. On phones this is in it's own Activity
and works great. On tablets this Fragment
is in a ViewPager
and the ListView
is never able to capture any of the the swipe events since they always go to the ViewPager
.
How would I go about making sure swipe gestures are captured by the ListView
to consume before they are passed to the ViewPager
?
P.S.
I am using this library for my swipe to dismiss gestures in my ListView
How would I go about making sure swipe gestures are captured by the ListView to consume before they are passed to the ViewPager?
Create a subclass of ViewPager
and override canScroll()
. If the supplied View
is the ListView
, return true
to have the touch events be given to the ListView
.
For example, here is a class I use in some samples for hosting maps in a ViewPager
:
/***
Copyright (c) 2013 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/
package com.commonsware.android.mapsv2.pager;
import android.content.Context;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.SurfaceView;
import android.view.View;
public class MapAwarePager extends ViewPager {
public MapAwarePager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x,
int y) {
if (v instanceof SurfaceView || v instanceof PagerTabStrip) {
return(true);
}
return(super.canScroll(v, checkV, dx, x, y));
}
}
Now, it is entirely possible that there may be more to getting your swipe-to-dismiss to work inside the ViewPager
, but I would start here.
这篇关于捕获刷卡解雇的ListView手势ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!