简体   繁体   中英

How to replace a view after I've inflated?

I have built my interface by using ViewStubs, which I inflate during onCreate.

But later in my app, I want to change the View completely, by loading different View into the same place. How do I achieve that?

Remove the old View via removeView() . Then inflate and add the replacement via 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM