Android TextView, ScrollView and gestures

This probably shouldn’t have taken me as long as it did, but I was pretty frustrated while trying to figure out why I couldn’t make my swipe gestures get recognized across the entire app.  Most of the activity screen responded, but not the TextView.  I added a gesture listener explicitly to the TextView and went through dozens of iterations.

Turns out, ScrollView objects absorb gestures – not just the scroll up and down as it needs to, but also the swipe (onFling message) from side-to-side.  I had wrapped my TextView in a ScrollView to allow it to scroll if there was too much text, but that meant limitations on my UI.

To resolve this, I removed the ScrollView wrapper on the TextView, and now the fling gestures are handled by the activity’s GestureHandler.  Ok, that was easy – now everything behaves as it should and the UI is consistent, which is good for the user experience.  No additional handler needs to be added for the view.   The result is that I need to ensure that my font is appropriately sized to not overflow the text box, but that can be handled.

Posted in Android permalink

About ProjectJourneyman

I am a software engineer that escaped the cubicle world at a large company to go solo with Android app development. My attention to detail and quality applies both to my apps and to my research on how to make money with Android. Now that I have the freedom to work on my own projects, I am documenting my efforts in the hopes that it will help other current or aspiring independent Android developers get the income they desire.

Comments

Android TextView, ScrollView and gestures — 2 Comments

  1. I am having the EXACT same problem. Any hopes of you posting your code for the TextView that allowed you to scroll normally & read a swipe action?

    • Actually, I don’t have scroll capability now. It’s fundamentally incompatible with the other gestures (without some complicated mechanism to transfer the gesture from the ScrollView to the other view objects). What I settled on is using side-to-side swipe to move between different text values, and using up-and-down gestures to make the font larger and smaller. All of my handler code is in onFling.

      If you need to scroll, maybe it’s possible to capture the gesture before it gets to the ScrollView and then manually scroll it – some kind of overlay. I decided it was easier to change my UI concept than to work around that bug. Good luck!