Android的变化的setContentView [英] Android change setContentView

查看:90
本文介绍了Android的变化的setContentView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要动态地设置内容查看我的活动。
因为有一次我使用XML作为内容查看,但anothertime我使用自定义视图内容查看。

I want to dynamically set the contentView in my activity. Because one time i use a xml as contentView, but at anothertime i use a custom view as contentView.

但我怎么改内容查看?

我读到了ViewFlipper能做到这一点,但viewFlipper是在一个XML文件中实现。这ViewFlipper内您可以添加不同的看法。

I read about that the ViewFlipper can do this, but a viewFlipper is implemented in a xml file. And within this ViewFlipper you can add your different views.

但我不之初认识他们,所以我不能他们都写在我的XML文件中。
你有什么想法?

But i dont know them at the beginning, so i cant write them all in my xml file. Do you have any idea?

感谢您

推荐答案

您可以致电的setContentView 随时 * ,不只是在的onCreate 。只要定义所有你想要在单独的XML文件的意见,并通过相关的ID时,它的时间切换。如果你想在code动态定义新的布局,然后做到这一点,叫的setContentView ,并通过新布局的根视图。

You can call setContentView at any time*, not just in onCreate. Just define all the views you want in separate XML files and pass the relevant id when it's time to switch. If you want to define the new layout dynamically in code, then do that and call setContentView and pass the root view of your new layout.

* 从技术上讲,你可以叫的setContentView 任何你在事件线程上执行的时间。否则,你需要使用一个处理程序来调用它。

* Technically, you can call setContentView any time you are executing on the event thread. Otherwise you need to use a Handler to call it.

这篇关于Android的变化的setContentView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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