match_parent不填父! [英] match_parent doesn't fill parent!

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

问题描述

我的LinearLayout里面的TableRow。
该得到的LinearLayout在code发起,是这样的:

I have LinearLayout inside TableRow. The LinearLayout get initiated in the code, this way:

LinearLayout  mainRowLayout = new LinearLayout(this);
mainRowLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TableRow tr = new TableRow(this);
tr.addView(mainRowLayout);

的问题是,所述的LinearLayout不能填满父(这是的TableRow)。
附加的图片说明了这个问题,如在Android的hirarchyViewer(绿色矩形是我的引号)。

The problem is that the LinearLayout doesn't fill the parent (which is the TableRow). The attached images illustrates the problem, as shown in the Android's hirarchyViewer (The green rectangles are my marks).

<一个href=\"http://picasaweb.google.com/113855881679019235357/UntitledAlbum#5558641368516190498\">\"LinearLayout形象

感谢。

推荐答案

在编程方式创建布局,你需要给父容器为孩子布置的说明。

When programmatically creating layouts, you need to give the parent container the layout instructions for the child.

// child element
LinearLayout mainRowLayout = new LinearLayout(this);

// parent element
TableRow tr = new TableRow(this);

// parent element's instructions (layout params for main row)
TableRow.LayoutParams lopForMainRow = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

tr.addView(mainRowLayout, lopForMainRow);

搏一搏:]

这篇关于match_parent不填父!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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