android以编程方式重绘布局 [英] android redraw layout programmatically

查看:63
本文介绍了android以编程方式重绘布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局有时无法正确放置元素.我尝试了许多解决方案,但独特的工作方法是从纵向旋转到横向,然后从横向返回到纵向.然后,版面会自动重新绘制,并且非常适合.我设置了方向|键盘,以便不重新加载内容,仅重新绘制内容.如何像风景肖像一样以编程方式重画内容?谢谢.

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.

我尝试了以下操作,但没有效果

I tried following and has no effect

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

活动已在onCreate setContentView(R.layout.main);

Activity has set main layout on onCreate setContentView(R.layout.main);

布局主"包含一个TabHost和Admob.布局视图"包含一个显示在tab1上的Web视图("id:myWebview").

Layout "main" contains a TabHost and Admob. Layout "view" contains a webview ("id:myWebview") that is shown on tab1.

并且还试图使它们无效!webview,布局主视图和布局视图以及崩溃

And also tried to invalidate them! webview, layout main and layout view and crashes

推荐答案

您尝试根视图?

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

这应该重新绘制整个布局.

This should redraw the whole layout.

这篇关于android以编程方式重绘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆