Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Streets Of Boston  
View profile  
 More options Oct 1 2012, 8:16 pm
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Mon, 1 Oct 2012 17:16:06 -0700 (PDT)
Local: Mon, Oct 1 2012 8:16 pm
Subject: Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

Hi everyone,

I have a ViewPager that contains pages, each page with a bunch of Buttons
(or clickable TextViews). When I set the buttons to 'setClickable(false)',
swiping the ViewPager to another page works fine all the time.

However, when the buttons are clickable (OnClick listener is set), the
ViewPager won't do anything if the user put his or her finger down on the
button when he or she starts a swipe or scroll. If the user swipes, the
button 'eats' all the touch-events (MotionEvents).

Is there a convenient way to make these buttons/textviews clickable and
make the ViewPager swipe even if the user puts his finger on a button
initially?
(I'd like to avoid hacks and using GestureDetectors if possible)

Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kostya Vasilyev  
View profile  
 More options Oct 2 2012, 12:47 pm
From: Kostya Vasilyev <kmans...@gmail.com>
Date: Tue, 2 Oct 2012 20:43:47 +0400
Local: Tues, Oct 2 2012 12:43 pm
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

Sounds like a bug in how ViewPager dispatches events (sorry for stating the
obvious). I'd consider looking at the source and comparing it to ScrollView
(which handles nested touchable areas just fine).

-- K

2012/10/2 Streets Of Boston <flyingdutc...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Oct 9 2012, 10:27 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Tue, 9 Oct 2012 07:27:31 -0700 (PDT)
Local: Tues, Oct 9 2012 10:27 am
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

Hi Kostya,

Thanks for your answer.

This bug (?) only happens on Jelly Bean (I don't have ICS devices to test
it on).
It works fine on Honeycomb and lower OS versions.

It seems there is indeed a regression of the ViewPager in JB (and possibly
ICS).

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piren  
View profile  
 More options Oct 9 2012, 11:31 am
From: Piren <gpi...@gmail.com>
Date: Tue, 9 Oct 2012 08:31:03 -0700 (PDT)
Local: Tues, Oct 9 2012 11:31 am
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

ViewPager is part of the support package and inherits from a ViewGroup , it
shouldn't matter much which OS version it runs on.
I have a similar setup and i dont experience this issue (using support
package v4, i assume you're using the same since you said you tested on
earlier os versions).
I can even press a button and see it switch to its pressed state and then
start a swipe without generating an onClick event.

What is your targetSdkVersion?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Oct 9 2012, 5:57 pm
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Tue, 9 Oct 2012 14:57:28 -0700 (PDT)
Local: Tues, Oct 9 2012 5:57 pm
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

The targetSdk is 11.
This is our hierarchy:

-ViewPager
  |
  +-NoSaveStateFrameLayout
       |
       +-ProfileGridView
              |
              +-ProfileGridViewRow
                      |
                      +-FrameLayout
                            |
                            +-TextView

Note that ProfileGridView contains one or more ProfileGridViewRows which
contains one or more clickable TextView  (i.e. our buttons).
The ProfileGridView and ProfileGridViewRow are custom LinearyLayouts: The
have their own measure and layout-logic. These two subclasses don't have
any method or logic to capture or handle touch-events.

Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piren  
View profile  
 More options Oct 10 2012, 9:38 am
From: Piren <gpi...@gmail.com>
Date: Wed, 10 Oct 2012 06:38:03 -0700 (PDT)
Local: Wed, Oct 10 2012 9:38 am
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

The thing is that being Clickable shouldn't have any impact in this
scenario. Although a clickable view always consumes the touch event, in
ViewPager's case it should intercept it when it recognizes a drag gesture
(see its onInterceptTouchEvent implementation).

You should override onTouch and onInterceptTouchEvent for all your custom
views and use logs to see how the events propagate through them (the proper
behavior would be the button intercepting onTouch and once your finger
moves enough in the X axes it should stop getting that event)

My best guess is that the ViewPager cancels the drag because it believes
your views have horizontal scrolling - I didnt dig all the way through, but
it seems to be basing that mostly on child view sizes... since you said you
have custom layout logic, i'm thinking it makes the ViewPager return the
wrong result. try debugging ViewPager's canScroll method.

they also have this comment in there: " // TODO: Add versioned support here
for transformed views. This will not work for transformed views in
Honeycomb+ ) "   Kind of suspicious :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leonidos  
View profile  
 More options Oct 15 2012, 7:01 am
From: Leonidos <mleoni...@gmail.com>
Date: Mon, 15 Oct 2012 04:01:25 -0700 (PDT)
Local: Mon, Oct 15 2012 7:01 am
Subject: Re: Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

I have the same issue with ViewPager and Jelly Bean. Trying to find a way
how to fix it )

I tested in on pre 4.x devices and everything was fine there...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Oct 31 2012, 7:11 pm
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Wed, 31 Oct 2012 16:11:33 -0700 (PDT)
Local: Wed, Oct 31 2012 7:11 pm
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

Thanks Piren!

Your answer led me into the right direction.

This was the problem:

The *ViewPager *contains *TextViews *as (grand-grand...) children. Before
it actually starts scrolling it asks if the touched child (or one of the
child's children) could scroll horizontally. If one of them does, the *
ViewPager* won't scroll horizontally itself. Instead, it lets this child
scroll.

The *TextView* implements a method called '*canScrollHorizontally(int)*'.
It uses the *mLayout *member to determine this method's return value.
Sometimes, the *mLayout.mWidth*  is 0x00100000 (= 1048576) and this weird
value causes this *canScrollHorizontallly *method to incorrectly return *true
*(instead of *false*).

The method canScrollHorizontally is only available for API-level 14 or
up... this may explain the issue...

For now, I just subclass my *TextView* that appear in the *ViewPager *and
override the *canScrollHorizontally *method, because I know the text in
these *TextViews *can never scroll horizontally.

public class MyTextView extends TextView {
...
@Override
public boolean canScrollHorizontally(int direction) {
return false;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Oct 31 2012, 7:32 pm
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Wed, 31 Oct 2012 16:32:19 -0700 (PDT)
Local: Wed, Oct 31 2012 7:32 pm
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

Update:

The weird 0x00100000 value is the value of *VERY_WIDE*, which is assigned
to the Layout's width if the *TextView*'s *mHorizontallyScrolling *field* *is
set to *true*.

Calling *setHorizontallyScrolling(false)* or setting the *
android:scrollHorizontally="false"* attribute in your XML does the trick as
well :-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piren  
View profile  
 More options Nov 1 2012, 4:16 am
From: Piren <gpi...@gmail.com>
Date: Thu, 1 Nov 2012 01:16:14 -0700 (PDT)
Local: Thurs, Nov 1 2012 4:16 am
Subject: Re: [android-developers] Buttons in ViewPager pages: Problem swiping/dragging pages when finger starts on top of Button. How can I fix this?

That is funny :-)

Glad i could help.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »