【问题标题】:GridLayout LayoutParams - programmatically apply weight and spanGridLayout LayoutParams - 以编程方式应用权重和跨度
【发布时间】:2016-07-28 09:25:24
【问题描述】:

我想以编程方式在 GridLayout 上应用 colspan 和 rowspan。我已经搜索了很多相同的内容。我有一些疑问:

  1. 还有其他方法可以通过编程方式创建 GridLayout 参数吗??
  2. 我可以使用 generateLayoutParams(AttributeSet attrs) 方法创建它吗?如果是,我该怎么做。如何以编程方式创建 AttributeSet。 任何帮助将不胜感激。 提前致谢!

【问题讨论】:

    标签: android android-layout android-gridlayout layoutparams


    【解决方案1】:

    如果您有高度和宽度,并且只想以编程方式创建 GridLayout 参数,请使用:

    GridLayout.LayoutParams param =new GridLayout.LayoutParams();
    param.height = LayoutParams.WRAP_CONTENT;
    param.width = LayoutParams.WRAP_CONTENT;
    layoutParams.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, item.getRowSpan());
    layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, item.getColumnSpan());
    
    gridlayout.setLayoutParams(param);
    

    【讨论】:

    • 在我的情况下不起作用。我的每个单元格都包含不同的视图。
    • 还有什么办法吗??因为这种方式变得越来越复杂
    • 那么 colspan 和 rowspan 我如何将它添加到它的孩子中
    • 现在检查它对您有帮助吗?我添加了行跨度和列跨度代码。
    • 你能帮我解决问题吗?stackoverflow.com/questions/68390342/…
    猜你喜欢
    • 1970-01-01
    • 2016-12-09
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 2014-04-22
    • 2015-05-06
    相关资源
    最近更新 更多