Jacksonkr
Jacksonkr

Reputation: 32247

Scrollview inside of a scrollview

BEFORE YOU SAY "Google says not to do this" PLEASE READ ALL OF MY QUESTION!!

The layout:

ScrollView -> RelativeLayout -> ScrollView -> RelativeLayout

The first ScrollView is necessary because form entries pull up the soft keyboard on some phones which hides the rest of the content. Having a ScrollView as the outer most container allows a user to scroll with the soft keyboard present.

The second ScrollView lower on the hierarchy is a ListView which is still scrollable.

I completely understand why devs are discouraged to have a ScrollView within another ScrollView. I need to figure out a way to get the two to work together. I tried disabling the outermost ScrollView when the inner most ScrollView get's a touch, but that didn't help.

Is there a way to get around this to where both will work (not at the same time of course)? I wouldn't even mind disabling the outermost ScrollView until the content page is changed again. There has to be a way..

Upvotes: 1

Views: 292

Answers (3)

Jacksonkr
Jacksonkr

Reputation: 32247

The answer is to programmatically intercept the touch events form the outer most scrollview. I am using a class that I found in another SOF about Disabling a ScrollView Programattically.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007584

Step #1: Remove the ScrollView.

Step #2: Make the first RelativeLayout be a header in your ListView via addHeaderView().

Step #3: Make the second RelativeLayout be a footer in your ListView via addFooterView().

The net effect is that the whole thing will be scrollable, without nested scrollable items.

Upvotes: 4

Anis BEN NSIR
Anis BEN NSIR

Reputation: 2555

It will only work when you set the android:layout_height to a fixed value for your second ScrollView. The best way is to set a size depending on device, for that it would be better to create layout for each supported screen size ( value on dp like 150 dp). you shoud create separate layout: layout-small, layout-normal, layout-large .... see this link for optimization of the fixed size: http://developer.android.com/guide/practices/screens_support.html

Upvotes: 0

Related Questions