【问题标题】:Auto adjust margin between TableRow to fit TableLayout vertically自动调整 TableRow 之间的边距以垂直适应 TableLayout
【发布时间】:2015-11-23 20:30:18
【问题描述】:

在我的应用程序中,我添加了 TableLayout。然后,我动态添加 TableRows。行数可以变化。 我需要的是垂直占据整个 TableLayout 的行。这里有一个解决方案:Android: Stretching rows in TableLayout programmatically

但是它增加了 TableRow 孩子的高度!我想在行之间添加额外的边距,而不是在表格行中拉伸视图的高度。

这可以通过编程方式调整边距吗?

【问题讨论】:

    标签: android android-layout tablelayout


    【解决方案1】:

    是的,您可以为表格布局设置边距。

    TableRow tr = new TableRow(this);  
    TableLayout.LayoutParams tableRowParams=
    new TableLayout.LayoutParams
    (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
    
    int leftMargin=10;
    int topMargin=2;
    int rightMargin=10;
    int bottomMargin=2;
    
    tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
    
    tr.setLayoutParams(tableRowParams);
    

    【讨论】:

    • 是的,我们可以设置边距,但我希望它动态完成,以确保填充整个 TableLayout,而不管我添加到布局中的行数。行之间的边距应该会自动调整!
    猜你喜欢
    • 2011-02-14
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2012-08-12
    • 2013-07-17
    相关资源
    最近更新 更多