如何克隆视图?

时间:2022-10-30 14:21:23

My question is almost exactly this question:

我的问题几乎就是这个问题:

Clone textview to append it to a ViewGroup

克隆textview将其附加到ViewGroup。

However, I was inflating a view, and then attempting to clone it at the object level for performance reasons (I don't want to parse XML every single time), so that answer doesn't help me. View.clone() is protected and it apparently doesn't have a copy constructor. Is there any way to do this?

但是,我正在膨胀一个视图,然后试图在对象级别上克隆它,以实现性能(我不想每次都解析XML),所以这个答案对我没有帮助。clone()是受保护的,显然它没有复制构造函数。有什么办法吗?

1 个解决方案

#1


101  

You cannot clone views, the way to do it is to inflate your View every time. Note that the XML is compiled into binary which can be parsed very efficiently.

你不能克隆视图,这样做的方法是每次都膨胀你的视图。注意,XML被编译成二进制,可以非常高效地解析。

#1


101  

You cannot clone views, the way to do it is to inflate your View every time. Note that the XML is compiled into binary which can be parsed very efficiently.

你不能克隆视图,这样做的方法是每次都膨胀你的视图。注意,XML被编译成二进制,可以非常高效地解析。