Software design

My layout sometimes doesn't position elements correctly. I tried many solutions, but a unique working one - it turns from portrait to landscape, and then returns from landscape to portrait. Then the layout is automatically redrawn and perfect. I set the keyboard orientation, so the content does not restart, it just redraws. How to redraw content programmatically, for example, landscape portrait? Thank.

EDIT: I tried to follow and has no effect

getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
getWindow().getDecorView().findViewById(android.R.id.content).requestLayout();

Activity set the main layout to onCreate setContentView(R.layout.main);

The "main" layout contains TabHost and Admob. The layout "view" contains a web view ("id: myWebview"), which is displayed on tab 1.

And also tried to annul them! web browsing, main layout and layout and crashes

+5
source share
4 answers

Have you tried root view ?invalidate()

findViewById(android.R.id.content).invalidate();

This should redraw the entire layout.

+5
source

When you change the screen orientation, Android recreates the current activity.

Try calling measure (int, int) or requestLayout () . Otherwise, there is no way to programmatically display the views.

+2
source
+1

If this is unsafe or bad practice, please correct me. I also tried all of these methods, and out of desperation, I decided to just try calling onCreate again, and it worked. So now I will use onCreate(null)to update my view when updating data. Again, please let me know if this is unsafe or bad practice and, if possible, a working alternative.

-1
source

All Articles