read

 

It’s been a while but I’m finally back with another one of my recent discoveries while working with Xamarin and Android. We are at the pointy end of our project so it has been hard to find the time to blog but luckily now that I do have some, I also have a lot of material banked up. Stay tuned…

I have list view inside a scroll view and I want to be able to be able to scroll both depending on which one I am touching.

In order to support devices with small screens, sometimes I resort to lazy man’s responsive design. I wrap the whole layout in a ScrollView element. While this works fine most of the time it does have an interesting time dealing with child elements that are also scrollable. The one I run into the most is the existence of a ListView inside a ScrollView.

Let’s say we have something like the following:

This will result in a screen that looks something like the following with the bottom list view as the only scrollable element and an inability to scroll down to the bottom TextView showing Vegetable Descriptions.

image

My next attempt to resolve this was to set the list views to a fixed height but the result is a little unexpected. For example if we set the list view heights to 250dp the scroll view will now operate properly but neither of the list views will scroll.

image

Then I found this article which describes the use of the OnTouchListener  to control how the layout scrolls when individual screen elements are touched. As I’m using Xamarin, most of these have been converted to events so I was able to attach a delegate and perform the same strategy as suggested in the article.

This results in a screen that is scrollable when not clicking on the list views while still being able to scroll the list views individually.

slamb2k


Published on

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Kym Phillpotts

I write about Xamarin Forms, mobile development or whatever else I might be concentrating on.

Back to Home