编程设置一个TextView的布局重 [英] Set the layout weight of a TextView programmatically

查看:198
本文介绍了编程设置一个TextView的布局重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要动态地创建的TableRow 对象,并将它们添加到 TableLayout 。 该的TableRow 对象有2个项目,一个的TextView 复选框。该的TextView 的项目需要有自己的布局权值设置为1推复选框项目的最右边。

I'm trying to dynamically create TableRow objects and add them to a TableLayout. The TableRow objects has 2 items, a TextView and a CheckBox. The TextView items need to have their layout weight set to 1 to push the CheckBox items to the far right.

我无法找到如何编程设置的TextView 项目的布局重量的文档。

I can't find documentation on how to programmatically set the layout weight of a TextView item.

推荐答案

您必须使用 TableLayout.LayoutParams 像这样的东西:

You have to use TableLayout.LayoutParams with something like this:

TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

的最后一个参数是重

The last parameter is the weight.

这篇关于编程设置一个TextView的布局重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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