【发布时间】:2014-03-11 19:24:26
【问题描述】:
好的,我已经搜索了它的解决方案,但是找不到。问题很简单。 Android 中有一个TableLayout,我在其中添加了几行。在最后一行,我添加了一个按钮。现在,问题是按钮的大小不是恒定的。我的意思是,它填满了列。如果上述数据占用了较长的列宽,则按钮的宽度也会相应增加。我也尝试过LayoutParams、setHeight、setWidth 功能,但这对我没有帮助..
如果有人能帮助我,我将不胜感激。
TableLayout table=new TableLayout(this);
TableRow tableRow=new TableRow(this);
Button button=new Button(this);
TableRow.LayoutParams trParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
Button.setLayoutParams(trParams);
tableRow.AddView(button);
table.addView(tableRow);
【问题讨论】:
-
分享你的xml文件....
-
我正在动态地执行此操作,即以编程方式。
-
TableLayout table=new TableLayout(this); TableRow tableRow=new TableRow(this);按钮按钮=新按钮(此); TableRow.LayoutParams trParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); Button.setLayoutParams(trParams); tableRow.AddView(按钮); table.addView(tableRow);
标签: android button tablelayout tablerow layoutparams