[英]How to replace a view after I've inflated?
I have built my interface by using ViewStubs, which I inflate during onCreate. 我通过使用ViewStubs构建了我的界面,我在onCreate期间对其进行了膨胀。
But later in my app, I want to change the View completely, by loading different View into the same place. 但是稍后在我的应用中,我想通过将不同的View加载到同一位置来完全更改View。 How do I achieve that?
我该如何实现?
Remove the old View
via removeView()
. 通过
removeView()
删除旧的View
。 Then inflate and add the replacement via addView()
. 然后充气并通过
addView()
添加替换addView()
。
Though if you're going to be bouncing back and forth a lot, consider using a FrameLayout
or ViewFlipper
or something to have both views loaded at once, only making one visible. 虽然如果您要来回弹跳很多,请考虑使用
FrameLayout
或ViewFlipper
或其他东西一次加载两个视图,仅使一个视图可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.