开发者

Calling inflate() multiple times in an Android view

开发者 https://www.devze.com 2023-01-07 05:49 出处:网络
I have a View that inherits from LinearLayout that inflates itself.After it has been created and inflated I wanted the ability to inflate a different layout.However, calling inflate() a second time se

I have a View that inherits from LinearLayout that inflates itself. After it has been created and inflated I wanted the ability to inflate a different layout. However, calling inflate() a second time seems to have no effect. Only if I close the activity and open it again is the state reflected in the UI.

Is it possible to call inflate multiple times to dynamically change the layout?

My in开发者_如何学运维flate code is pretty simple:

layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.my_layout, this, true);


Is it possible to call inflate multiple times to dynamically change the layout?

Try removing your child views first. Right now, you are appending the new stuff after the old stuff, AFAICT.

0

精彩评论

暂无评论...
验证码 换一张
取 消