简体   繁体   中英

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..

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.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM