Android如何以编程方式创建视图 [英] Android How to create a View Programmatically

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

问题描述

我需要以编程方式创建视图.控件(按钮,标签等)及其位置仅在运行时知道.

I need to create a view programmatically. The controls(buttons, labels, etc.) and their positions are known only at runtime.

在这里,我发现以编程方式定义布局": http://mobile. tutsplus.com/tutorials/android/android-layout/

Here I found "Defining a Layout Programmatically": http://mobile.tutsplus.com/tutorials/android/android-layout/

但是我需要能够在确切的位置绘制组件,以便LinearLayout,TableLayout等对我不起作用.

but I need to be able to draw components at exact locations so LinearLayout, TableLayout etc. doesn't work for me.

我该怎么做?

推荐答案

创建自定义 ViewGroup ;这使您可以手动管理每个孩子(按钮,标签等)的放置.在2009年的google IO事件中检查 vid使您的Android UI快速高效" ",具体是从大约43分钟开始,以获取更多详细信息.

Create a custom ViewGroup; this allows you to manage placements of each of the children you have (buttons, labels, etc) manually. Check this vid from the google IO event in 2009 titled 'Make your Android UI Fast and Efficient', specifically from about 43 minutes onward for more details.

这篇关于Android如何以编程方式创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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