创建控件编程 [英] Create widget programmatically

查看:116
本文介绍了创建控件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,Android部件需要RemoteViews,而不是观,之类的活动。

我的问题:有没有办法完全避免XML,并建立整个布局用java code

替代问题:我能以某种方式检索查看,就像我会使用 findViewById(INT)?例如:的LinearLayout的LinearLayout =(的LinearLayout)findViewById(R.id.xxx); 这样我可以访问的基地布局,并操纵不过我想

谢谢!


解决方案

  

有没有办法完全避免XML,并建立整个布局用java code?


没有,对不起。 RemoteViews 在很大程度上依赖于布局的XML资源。虽然有一个 addView()方法,转身又增加了 RemoteViews ,并让你回到原点从你开始。


  

我可以以某种方式检索查看,就像我会用findViewById(INT)?


没有,因为没有查看在你的进程。您配置通过各种setter方法​​上的小部件 RemoteViews

As far as I understand, android widgets need RemoteViews, instead of View, like activities.

My question: is there any way to completely avoid xml, and build the whole layout with java code?

Alternative question: can I somehow retrieve a View, like I would use findViewById(int)? For example: LinearLayout linearLayout=(LinearLayout)findViewById(R.id.xxx); This way I could access the base layout, and manipulate however I want to.

Thanks!

解决方案

is there any way to completely avoid xml, and build the whole layout with java code?

No, sorry. RemoteViews relies heavily on layout XML resources. While there is an addView() method, it turns around and adds another RemoteViews, and that puts you right back where you started from.

can I somehow retrieve a View, like I would use findViewById(int)?

No, because there is no View in your process. You configure the widgets via the various setter methods on RemoteViews.

这篇关于创建控件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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