我有自定义类的代码,允许2dscrolling ...排序。除了一件事,一切都符合我的喜好。点击屏幕时,水平滚动(水平滚动视图嵌套在此视图中)仍然停止。但是,当触摸屏幕时,不再停止垂直滚动。我怎样才能做到这一点?我应该将代码添加到我的Customscrollingview还是java中进行活动?
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
public class ParentScrollView extends ScrollView {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
@SuppressWarnings("deprecation")
public ParentScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if( mGestureDetector.onTouchEvent(ev)&super.onInterceptTouchEvent(ev)){
return true;
}else{
return false;
}
}
// Return false if we're scrolling in the x direction
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float
distanceY) {
if(Math.abs(distanceY) > Math.abs(distanceX)) {
return true;
}
return false;
}
}
}
答案 0 :(得分:0)
我用过
@Override
public boolean onTouchEvent(MotionEvent ev)
{
switch (ev.getAction())
{
case MotionEvent.ACTION_UP: this.smoothScrollBy(0, 0);
break;
}
return super.onTouchEvent(ev); }
现在它更加可行。滚动操作的可能性要小得多,因为它已经被甩掉了#34;。