Framelayout Child View Not Updating Correctly On Resize
I have an Android application in which the root view is a FrameLayout which on rotation is kept and resized rather than recreated. Among the children of the FrameView is one custom
Solution 1:
As I had suspected based on the log output, something in the guts of the UI has not been updated by the time onSizeChanged()
gets called. I haven't figured out what, but the takeaway is that the LayoutParams
stuff needs to be deferred until everything else has finished. This can be done by wrapping the code into a Runnable
and post()
ing that to the FrameLayout
:
staticbooleanisBandShowing= ...; // whether the band should be shownstaticbooleanisPortrait= ...; // whether we are in portrait mode, controls where the band is displayedstaticinthorizontalBandHeight= ...; // default height for band in portrait modestaticintverticalBandWidth= ...; // default width for band in landscape mode
frameLayout.post(newRunnable() {
@Overridepublicvoidrun() {
bandView.setVisibility(isBandShowing ? View.VISIBLE : View.GONE);
LayoutParamsbandLayoutParams=newFrameLayout.LayoutParams(
isPortrait ? LayoutParams.MATCH_PARENT : verticalBandWidth, // X
isPortrait ? horizontalBandHeight : LayoutParams.MATCH_PARENT, // Y
Gravity.BOTTOM | Gravity.RIGHT);
bandView.setLayoutParams(bandLayoutParams);
}
});
That solved it.
Post a Comment for "Framelayout Child View Not Updating Correctly On Resize"