Monday, May 17, 2010

[android-developers] Changing size of content in HorizontalScrollView when phone is rotated by overriding onConfigurationChanged

Hello fellow Androiders...

I have a problem with resizing content in a HorizontalScrollView when
the phone is rotated. I'm overriding onConfigurationChanged in my
activity containing the HorizontalScrollView, since I want to handle
the resizing myself and tell the scrollview when to resize. However,
I'm having great problem finding where i should put the resizing of
the content. I obviously need to do it after it has changed its width
but no matter where I do it it seems to be too early. The
HorizontalScrollView it self has FILL_PARENT as width and a fixed
height. The idea is that it should always fill the screen width-wise,
while having several cells of content, each as wide as the
HorizontalScrollView itself.

The content in my HorizontalScrollView consists of one LinearLayout
(let's call it wrapperLayout) with several LinearLayouts inside it.
When the phone rotates I simply want to change the width of all the
LinearLayouts inside the wrapperLayout. This is easy to do and works
great when I test the resizing code by putting it in
onInterceptTouchEvent(MotionEvent ev), that is the views are resized
just as they are supposed to when I touch the HorizontalScrollView.

The difficulty appears when I try to find a good spot to execute the
resizing code, so that the resizing happens automatically when the
phone is rotated. I have tried all possible combinations of
requestLayout, onSizeChanged, onLayout, onConfigurationChanged and a
few others and varying their calls to super (if any) before and after
the resizing code. I can not get this to work (the views are not
resized even though the resize code is executed) and it is really
frustrating. I've done a lot of logging to make sure the
HorizonalScrollView really has changed width before calling my resize
code but to no avail. It appears that no matter how late I try too
resize it is too early.

Does anyone have any clue as to what is going on? What methods are
called and in what order when I handle the onConfigurationChanged by
myself like this?

Thanks in advance

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate