简体   繁体   English

膨胀后如何替换视图?

[英]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. 虽然如果您要来回弹跳很多,请考虑使用FrameLayoutViewFlipper或其他东西一次加载两个视图,仅使一个视图可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为膨胀视图设置行为? - How do I set the behavior for an inflated view? 膨胀后,Android找到一个视图 - Android find a view after it is inflated 用ButterKnife绑定所有视图后如何绑定活动中膨胀的视图 - How to bind view inflated in activity after bind all the views with ButterKnife 我如何设置膨胀的视图宽度,它的一半是父视图? - How can i set inflated view width, half of it's parent? 如何从膨胀的布局中获取视图的参考 - How can I get a reference of a view from a inflated layout 调用show()之后,在对话框片段中修改膨胀的膨胀视图 - Modfiying inflated inflated view in a dialogfragment after calling show() 我将视图膨胀了 5 次,膨胀的视图有一个 EditText,现在我在屏幕上有 5 个 EditText,如何从这些 EditTexts 中获取文本 - I inflated a view 5 times, the view which was inflated had a EditText, now i have 5 EditText on the screen, how to get the text from those EditTexts 如何引用膨胀的视图元素? - How to reference the inflated view elements? 如何将膨胀的视图转换为位图? - How to convert a inflated View to Bitmap? 如何在充气视图上显示上下文菜单? - How to show contextmenu on inflated view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM