
HorizontalScrollView
嵌套ScrollView导致滑动卡的情况,急横向水平滑动的View和垂直水平滑动的View,都在接收处理滑动时间,但是这种情况下触摸事件就会发生
冲突。导致滑动非常卡,甚至出现程序停止响应。这种情况下我们需要重写view。下面是两个简单的例子,重写水平滑动View只接收水平方向上滑动的事
件。我们使用手势GestureDetector来作区分
import androidcontentContext;
import androidutilAttributeSet;
import androidviewGestureDetector;
import androidviewGestureDetectorSimpleOnGestureListener;
import androidviewMotionEvent;
import androidviewView;
import androidwidgetHorizontalScrollView;
public class CustomHScrollView extends HorizontalScrollView{
private GestureDetector mGestureDetector;
private ViewOnTouchListener mGestureListener;
private static final String TAG = "CustomHScrollView";
/
@function CustomHScrollView constructor
@param context Interface to global information about an application environment
/
public CustomHScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
mGestureDetector = new GestureDetector(new HScrollDetector());
setFadingEdgeLength(0);
}
/
@function CustomHScrollView constructor
@param context Interface to global information about an application environment
@param attrs A collection of attributes, as found associated with a tag in an XML document
/
public CustomHScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mGestureDetector = new GestureDetector(new HScrollDetector());
setFadingEdgeLength(0);
}
/
@function CustomHScrollView constructor
@param context Interface to global information about an application environment
@param attrs A collection of attributes, as found associated with a tag in an XML document
@param defStyle style of view
/
public CustomHScrollView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
mGestureDetector = new GestureDetector(new HScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return superonInterceptTouchEvent(ev) && mGestureDetectoronTouchEvent(ev);
}
// Return false if we're scrolling in the y direction
class HScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(Mathabs(distanceX) > Mathabs(distanceY)) {
return true;
}
return false;
}
}
}
为其实现View 添加滚动(scroll)相关的APIs
水平方向上, 计算滚动条 表示的 范围 。
范围可以用 任意单位 计量,但必须与其他函数所用单位 一致 :
( computeHorizontalScrollOffset(); computeHorizontalScrollExtent(); )
默认范围 :是此视图的绘图宽度。
返回值 :滚动条表示的总范围
水平方向上, 计算 滚动条 滑块 在滚动条范围中的 偏移量 。此值 用于计算滑块 在轨道中的 位置
范围所用单位需与其它函数一致。
默认偏移量 :是此视图滚动的偏移量。
返回值 :滑块的偏移量
水平方向上, 计算滑块 在滚动条范围中的 大小 。此值 用于计算滑块在轨道中所占的长度 (可视区域长度)
范围所用单位需与其它函数一致。
默认大小 :是此视图的绘图宽度。
返回值 :滑块的大小(可视区域长度)
方向改为垂直,其余同上
RecyclerView
ListView
通常为带有滑动功能的ViewGroup,都实现了此接口
1 Toast是Android中用来显示显示信息的一种机制,和Dialog不一样的是,Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失。默认效果,代码为:ToastImageToast); imageTitleToast); titleTextToast); textsetText("完全自定义Toast"); toast = new Toast(getApplicationContext()); toastsetGravity(GravityRIGHT GravityTOP, 12, 40); toastsetDuration(ToastLENGTH_LONG); toastsetView(layout); toastshow();5其他线程,代码为:new Thread(new Runnable() { public void run() { showToast(); } })start();
以上就是关于Android ListView的Item里有horizontalScrollView,怎么判断是点击事件并拦截,如果是横向滑动就放过。全部的内容,包括:Android ListView的Item里有horizontalScrollView,怎么判断是点击事件并拦截,如果是横向滑动就放过。、Android API 全解析(一):interface ScrollingView、android开发中如何实现将手机平移的方向toast出来求完整代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)