AndroidDeveloperLB/AutoFitTextView

Special case when used inside ViewPager

Closed this issue · 2 comments

The code generally works great, but it's important to know that when used inside a ViewPager, the sliding gesture may not work unless special precautions are taken. The problem is that by default, singleLine is set to true and that also causes scrollHorizontally to be set to true. So in order to work around this, make sure in your XML layout you control the line count with maxLines and not singleLine property:

android:maxLines="1"
android:singleLine="false"

Can you please explain what's wrong with what I did?
What should I do?

Nothing is necessarily wrong with what you did, but if scrollHorizontally is set to true - and it is by default in your code when singleLine is set to true, then swipe gestures won't get sent to the underlying ViewPager (if used inside a ViewPager!). The workaround I propose solves this corner-case.