【问题标题】:How to set the main LinearLayout width to the maximum size w/o xml?如何将主要 LinearLayout 宽度设置为 w/o xml 的最大尺寸?
【发布时间】:2012-01-01 01:39:37
【问题描述】:

我想编写在代码中创建布局的应用程序(没有 xml-layout 文件)。在xml文件中我可以写:

android:layout_width="fill_parent"

我应该在代码中写什么? 我寻找类似的东西:

LinearLayout ll = new LinearLayout(this);
ll.set?????? (????) ;

【问题讨论】:

  • 请阅读关于签名的常见问题解答stackoverflow.com/faq#signatures
  • 嗨,Sameera,我读到了。什么意思?
  • 由于 SO 的政策,我不得不从帖子中删除您的签名。我刚刚从常见问题解答中为您提供了该政策链接。 :)
  • 嗨 Sameera,我不知道我有一个,所以没关系 :-)。

标签: android android-widget


【解决方案1】:

你可以看看这个。

LinearLayout l = new LinearLayout(this);
l.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

你也可以查看this作为例子

【讨论】:

    猜你喜欢
    • 2011-04-11
    • 2018-11-08
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2013-04-30
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多