如何克隆视图? [英] How do I clone a View?

查看:30
本文介绍了如何克隆视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My question is almost exactly this question:

克隆 textview 以将其附加到 ViewGroup

但是,我正在膨胀一个视图,然后出于性能原因尝试在对象级别克隆它(我不想每次都解析 XML),所以这个答案对我没有帮助.View.clone() 是受保护的,它显然没有复制构造函数.有没有办法做到这一点?

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 被编译为可以非常有效地解析的二进制文件.

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.

这篇关于如何克隆视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆