I'm developing a widget where the portrait and landscape layouts are saved in /layout and /layout-land respectively. each layout file is named the same, but has been modified for formatting changes based on their orientation differences.
When I start a widget in one of the orientations and keep it there, it works fine...but the moment i switch orientations, the whole layout goes haywire.
Now, after searching the web I have found out that the Android system loads the latest RemoteView from cache. Aka, if i started the widget it in landscape, the landscape layout gets cached and used when changing oritentation.
I've tried everything I can think of to stop this from happening, but to no avail. Does anyone know if it is possible to clear the Android RemoteView cache and FORCE it load the corrected layout??
Thanks
EDIT:
I have found a solution, albeit a bit hacky...
I created a "wrapper" layout that only has a LinearLayout in it with an ID, and then created sub-layouts where the landscape versions have a _land at the end of the name.
in the onUpdate method and the service that updates the widget, i check the orientation of the screen, then programatically select either the _land or non-_land version, and add it to the wrapper layout.
I can开发者_开发百科't believe Google didn't make this easier to do, and its incredibly frustrating that I have to force such programatic behaviour out of something that should seem natural to do using XML configurations.
You might need to use layout-land
and layout-port
as the directories (as opposed to layout
and layout-land
) to make it work correctly.
精彩评论