when i tried to use scrollview or webview in a scrollview, the inside scrollview or webview can not scroll. I can scroll with trackball but I can't scroll with touch. Do you have any idea about this issue?
I found something and it works for me. I wanted to share. Here it is,
I have one scrollview and listview. listview inside scrollview. Scrollview-> RelativeLayout-> Listview. That listener belongs to Listview;
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
ScrollView().requestDisallowInterceptTouchEvent(true);
}
return false;
}
Android does not support using ScrollViews or ListViews inside each other. It's possible to do, but it's A Bad Thing (TM), according to Google developers.
Search SO for similar problems with ListViews, and you'll find several discussions + suggestions on how to hack around the limitations of the OS. However, I would strongly suggest you reconsider your layout to try and find some other way to handle your layout.
ScrollView supports only one direct child; it can be either a LinearLayout or a RelativeLayout. If you have more than one children the scroll wouldn't work properly.
Related
It's my understanding that Android event propagation goes from parent to child, that is to say, it starts with the outermost element and inwards from there. My question is, why is it that when I try to scroll vertically a listview that is inside a viewpager that is wrapped on a scrollview, the listview moves, and not the viewpager.
Okay, let me rephrase that:
I'm trying to create a menu that appears when the user pulls down the view pager, let me make that even clearer:
Scrollview
My custom Menu
ViewPager (with three fragments, all of them have a lisview)
ListView
I understand that what I'm trying to do is a bit odd, but bear with me just for this time. :)
What can I do to "disable" momentarily the list views scrolling.
Thanks
It seems you have to override the scrolling event. A good webpage is Disable scrolling in Android ListView .
Mainly look at dispatchTouchEvent. Snippet of it:
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int actionMasked = ev.getActionMasked() & MotionEvent.ACTION_MASK;
if (actionMasked == MotionEvent.ACTION_MOVE) {
// Ignore move events
return true;
}
Personally I wish it is simpler than this like disabling scroll method.
I have a ViewPager that contains two fragments. In any of the fragments I can touch a place, swipe to switch to another fragment. One of the fragments contains a list. Items in the list contains one TextView and one ImageView. The issue is, if you dragging has been started from tapping the ImageView, it's OK. But if it's been from the TextView, the drag was never known to the ViewPager, as a result the 'smooth switching' never happens.
Any clue on this?
EDIT
This picture is to show how my GUI is. If the drag has been started from TextViewE, it doesn't begin.
This thing bothered me too, but I've managed to find the answer.
Basically, the case is: if the view can scroll horizontally, it intercepts the horizontal motion event and ViewPager is not able to process it anymore.
Since API Level 14 TextViews have android:scrollHorizontally property (and setHorizontallyScrolling(boolean) method), which, if set to true, causes the TextView to intercept horizontal scroll motion events.
You may set it to false either in XML or right in the code, but watch out: android:singleLine property forces android:scrollHorizontally to be set to true! Very tricky point! But fortunately, you usually able to safely replace single line property with android:maxLines="1" and necessary ellipsize value.
Good luck!
you can override onTouchEvent() of the TextView:
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return false;
}
return super.onTouchEvent(event);
}
I want to use a ListView (and have done this successfully before) containing custom Views.
Basically these custom views are vertical sliders, obviously conflicting with the natural behaviour of the ListView.
I fill it with my custom Views from an Adapter, and these react to the touches on the Items,
but once I move my finger more than a few pixels, it will scroll, and the custom View will not receive any touch-events anymore.
How can I (nicely) prevent the ListView from scrolling, when I touch my own components?
Can I somehow disable ListView Selection, and just forward the touches to the Items, but still use the scrolling behaviour?
Thank you in advance.
To prevent the scrolling of listview you can inplement on touch listener as follows
listView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_MOVE)
{
return true;
}
return false;
}
});
hope it will work and if it us useful to you give vote
You can intercept all touch events using onInterceptTouchEvent() in your root layout (one that contains the ListView, like a FrameLayout) as found here.
What you do there is capture the motion events (return true when a MotionEvent.ACTION_DOWN comes in), capture the following event in onTouchEvent(), decide whether the motion is meant for the list items or the list itself and accordingly dispatch the events.
Don't expect this to work easily. Understanding the flow of motion events and the interaction between onInterceptTouchEvent() and onTouchEvent() is challenging and making it work even more so. But I'm confident that this is a feasible way to solve your problem.
I'm writing an application in which i have to scroll different images one after another across the screen. In order to do that, i create a list of 10 ImageView items. These image view items are placed one after another like train coaches.
The question is how to scroll them from left to right. I thought of using scrollview, but it can accept only one child component and does vertical scrolling.
There is a Scroller class, but i'm not sure how to use it, i mean what does it scroll? I dont see any method like Scroller.scroll(view).
Another approach which i though was to user Layout animation such as TranslateAnimation, but then the end result is kind of shaky.
Can anyone point me to some sample of scrolling image from left to write. I don't want to use the gallery components because it defeats the objective of the application.
Thanks
you can use HorizontalScrollView with a horizontal LinearLayout inside, containing your ImageViews.
You can use HorizontalScrollView with a horizontal LinearLayout inside, containing your ImageViews.
You can do one more thing to override the following method in horizantalScrollview
#Override public boolean onTouch(View v, MotionEvent event)
{
//...
}
Gallery widget would much help you
I am developing an Android app with an Activity with a ScrollView that contains, among other stuff, a HorizontalScrollView. When I touch the HorizontalScrollView I want to disable vertical scrolling of the outer ScrollView. How do I achieve that?
Thanks
Markus
Have a look at
public boolean onInterceptTouchEvent(MotionEvent ev) { }
Of the ScrollView classes.