Android- Scrollview : change layout position by dragging
I create Scrollview with 10 layout. I want to change the layout position by dragging.
layout_view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {
...
The problem is when i dragging DOWN/UP (When I dragging right/left it's work perfect):
1) MotionEvent.ACTION_CANCEL happen
2) the Scrollview is moving
1)How Can I disable Scrollvi开发者_StackOverflowew scrolling when I dragging my layout?
2) Do you have any idea how to stay in layout without getting MotionEvent.ACTION_CANCEL?
Thanks
Override ScrollView with one that you can enable/disable
//A scrollview which can be disabled during drag and drop
public static class OnOffScrollView extends ScrollView {
private boolean on = true;
public OnOffScrollView(Context context) {
super(context);
}
public OnOffScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public OnOffScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//turn on the scroll view
public void enable() {
on=true;
}
//turn off the scroll view
public void disable() {
on = false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (on) {
return super.onInterceptTouchEvent(ev);
}
else {
return false;
}
}
}
Disable it in your MotionEvent.ACTION_DOWN
case, enable it again in the MotionEvent.ACTION_CANCEL
and MotionEvent.ACTION_UP
cases
精彩评论