Remove scroll event for a ScrollView child - android

Is it possible to remove scroll event for a layout that is inside a ScrollView?
I have the following layout hierarchy:
ScrollView
RelativeLayout
LinearLayout
TableLayout
RelativeLayout
GestureOverlayView
I want to remove the scroll event for the RelativeLayout that contains a GestureOverlayView so that when the user draws a vertical line, the event is not intercepted as scroll but as drawing.

I don'y know you still need that or not but here is the answer I tested.
this is how you prevent the parent View from stealing touchEvent of a child view:
childView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.childView) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
you can go up in parents by:
v.getParent().getParent ....

Related

HorizontalScrollView inside Movable View

I have a movableView(moves with finger touch movement) of 400*400, it has a horizontal view at bottom (400*100). When I want to scroll horintalScrollView to see the list, my movableView is moving, but horintalSrollView is not taking any touchEvent.
I want it like, when I am touching horizontalScrollView, only it should scroll. And when not touching it and want to move my movableView it should move.
Any suggestions would be helpful.
Thanks
Try this logic...
scrollView.setOnTouchListener(new OnTouchListener() {
// Setting on Touch Listener for handling the touch inside movableView
#Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent move on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

ListView scrolling not working inside scrollView. it is creating jerk

i have integrated listView inside the scrollView. im facing issue while vertical scrolling. how to fix this issue ?
ListView inside the scrollView is an bad programming practice. ListView aleary has its own scrolling functionality and you are again embedding it into the scrollView that why it is creating an jerk.
Don't use listView inside the scrollView.
If you want to scroll let's say listView and not whole scrollView you could try this code. However, it is not good idea to place listView inside of scrollview. Your users may find it uncomfortable.
yourListView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.yourListView) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});

Perform something onTouch if parent ScrollView doesn't handle it

OK, this might be trivial, but I can't figure out how to do it.
We have a container scrolling view, a subclass of ScrollView, and this view has a child view (among others) which should listen to touch events.
In particular, what I'd like to do is:
childView is clicked and MotionEvent.ACTION_DOWN comes;
check if that event is a scrolling event, i.e., check if that action would start a scroll on the scrollView;
if so, let the scrollView handle it and do nothing; if not, i.e. if the click upon childView did not start a scroll onto the parent view, do something.
Any ideas?
Pseudocoding, it should be something like:
ScrollView scrollView = ...;
View childView = scrollView.findViewById(...):
childView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
if (scrollView.onTouchEvent(event)) {
// event was handled by the view
return false;
} else {
// do something
return true;
}
}
return false;
}
});
As you can see I have not much insight on how motion events work.

Swipe left and right in scrollView

I have some layouts inside a scrollView. Those layouts have to be "swipable" in left and right directions but it creates some conflicts with the scrollView.
I've tried to disable the scrollView while touching on one of those layouts but in that case my scrollView is almost always disable.
This is how my layout looks like.
What I've now :
private void swipePositionsEvent() {
for(LinearLayout layout : layouts){
layout.setOnTouchListener(new OnSwipeTouchListener(this,
((ScrollView)findViewById(R.id.scroll_view_confirm_games))){
public void onSwipeRight() {
flipper.showNext();
}
public void onSwipeLeft() {
flipper.showPrevious();
}
});
}
In OnSwipeTouchListener:
Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
scrollView.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
scrollView.requestDisallowInterceptTouchEvent(false);
break;
}
return gestureDetector.onTouchEvent(event);
}
Thank you!
Detect whether the first movement is horizontal or vertical before you disable the scrollview.

Scrollview inside scrollview in android

I am having scrollview inside another scrollview. I want to scroll inner scrollview but outer scrollview is only scrolled.how to solve this problem?
Thanks.
sv01 = (ScrollView) findViewById(R.id.popup_sf_event_scroll_01);
sv02 = (ScrollView) findViewById(R.id.popup_sf_event_scroll_02);
sv02.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP)
sv01.requestDisallowInterceptTouchEvent(false);
else
sv01.requestDisallowInterceptTouchEvent(true);
return false;
}
});
in scroll view take one layout and add another scrollview in that layout coz scrollview can hold only one child in it. So that inner scrollview can move for what it is holding in it.

Categories

Resources