Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView inside ViewPager intercepts touch events

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. enter image description here

like image 877
tactoth Avatar asked Mar 18 '13 06:03

tactoth


1 Answers

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!

like image 161
pechenie Avatar answered Sep 27 '22 22:09

pechenie