My layout sometimes does not position elements properly. I tried a lot of solutions but unique working one is rotate from portrait to landscape and then return from landscape to portrait. Then layout is automaticaly redrawed and fits perfectly. I set orientation|keyboard so content is not reloaded, only redrawed. How to redraw content programmaticaly like landscape-portrait does? Thank you.
EDIT: I tried following and has no effect
getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
getWindow().getDecorView().findViewById(android.R.id.content).requestLayout();
Activity has set main layout on onCreate setContentView(R.layout.main);
Layout "main" contains a TabHost and Admob. Layout "view" contains a webview ("id:myWebview") that is shown on tab1.
And also tried to invalidate them! webview, layout main and layout view and crashes
Did you try to invalidate()
the root view?
findViewById(android.R.id.content).invalidate();
This should redraw the whole layout.
When screen orientation changes, Android recreates the current Activity.
Try calling measure(int, int) or requestLayout(). Otherwise there is no chance to programmatically relayout views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With