Android - 在不同的活动中创建和重用视图
我几乎可以肯定,好的做法是在一个活动中使用视图,而不是(在活动之间)移动它太多。
我的意思是,是否有可能(以编程方式)创建一个视图,然后将其保留在某个单例对象中,然后尝试将其添加到不同活动中的另一个视图?
我个人的感觉是,这是非常错误的做法,但我需要检查一下,有一家公司要求他们的 SDK 进行类似的做法,在我反对他们之前,我想确定一下。
任何帮助表示赞赏, 丹尼尔
I'm almost sure that the good practice is to use a View in one Activity, and not move it around too much (between Activities).
I mean, is it possible at all to create (programatically) a View, then keep it in some singleton object, and then try to add it to another View in a different Activity?
My personal feeling is that this is quite wrong practice, but I need to check it, there is a company requesting similar practice with their SDK, and before I oppose them, I want to be sure.
Any help appreciated,
Danail
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不构建一个自定义视图?无论它是在
ViewGroup
中使用的简单小部件,还是它自己的ViewGroup
,它都可以是您可以重用和自定义的东西!显然,您可以提供不同的构造函数/设置器来根据您的喜好自定义
View
。 (即,为背景指定不同的位图,为标题文本指定不同的字符串......)Why not build a custom View? Whether it is a simple widget that is used within a
ViewGroup
, or it is aViewGroup
of its own, it could be something that is reusable and customizable by you!Obviously, you could provide different constructors/setters to customize the
View
to your liking. (ie, specify different bitmaps for backgrounds, different strings for title text...)