我正在尝试实现一个表格布局,其下面有一个标题和一堆行。 我选择了GridLayout(android.support.v7.widget.GridLayout),因为某些元素需要跨越多个列(但这些问题与问题无关)。
我的标题单元格每个都包含一个带有一堆TextView的LinearLayout,它们是动态填充的代码,例如,请看下面的图像。 第二行应包含分隔符,它是一个简单的视图,应该跨越我的标题列(3)。
问题是分隔符的宽度 - 如果我选择MATCH_PARENT,它将推动GridLayout将整个剩余空间填充到右侧。 网格需要包含内容并水平居中。 在我看来,网格的布局(WRAP_CONTENT)和分隔线的布局(MATCH_PARENT)之间存在冲突。
如何在不对其进行硬编码的情况下修复分隔线的宽度?
http://i61.tinypic.com/2415eg5.png
红色,我的LinearLayouts(标题),绿色,GridLayout本身,底部的细蓝线是分隔线。
谢谢,MO
解决方案(如下所示):我必须将分频器的列权重设置为1,而不指定宽度(实际将其设置为零)。 由于我在代码中处理所有这些的特定要求,解决方案是手动实例化GridLayout.LayoutParams类并使用
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)希望这有助于将来的其他人。
I'm trying to implement a tabular layout that has a header and a bunch of rows underneath it. I've chosen the GridLayout (android.support.v7.widget.GridLayout) as there's some requirements for some elements to span multiple columns (but those are of no concern to the question).
My header cells each contain a LinearLayout with a bunch of TextViews, they're dynamically filled in code,for the sake of example, have a look at the image below. The second row should contain the divider which is a simple view, that should span my header columns (3).
The problem is the width of the divider - if I choose MATCH_PARENT, it will push the GridLayout to fill the whole remaining space to the right. The grid needs to wrap the content and center itself horizontally. It seems to me there's a conflict between the grid's layout (WRAP_CONTENT) and the divider's layout (MATCH_PARENT).
How can I fix the width of the divider without hardcoding it?
http://i61.tinypic.com/2415eg5.png
In red, my LinearLayouts (header), green, the GridLayout itself, the thin blue line at the bottom is the divider.
Thanks, MO
SOLUTION (as provided below): I had to set the column weight for the divider to 1, without specifying a width (actually setting it to zero). Because of my specific requirement to handle all of these in code, the solution was to manually instantiate the GridLayout.LayoutParams class and use
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)Hope this helps others in the future.
最满意答案
如果你将宽度设置为0dp然后给它android:layout_weight="1" (你可以给它任何你想要的重量)它应该填满所有可用的空间而不是如果我理解你正确的问题就推动你的界限
If you set the width to 0dp then give it android:layout_weight="1" (you could give it any weight you want) it should fill all the available space and not push your bounds if I understand what you are asking correctly
android GridLayout分隔符行(android GridLayout divider row)我正在尝试实现一个表格布局,其下面有一个标题和一堆行。 我选择了GridLayout(android.support.v7.widget.GridLayout),因为某些元素需要跨越多个列(但这些问题与问题无关)。
我的标题单元格每个都包含一个带有一堆TextView的LinearLayout,它们是动态填充的代码,例如,请看下面的图像。 第二行应包含分隔符,它是一个简单的视图,应该跨越我的标题列(3)。
问题是分隔符的宽度 - 如果我选择MATCH_PARENT,它将推动GridLayout将整个剩余空间填充到右侧。 网格需要包含内容并水平居中。 在我看来,网格的布局(WRAP_CONTENT)和分隔线的布局(MATCH_PARENT)之间存在冲突。
如何在不对其进行硬编码的情况下修复分隔线的宽度?
http://i61.tinypic.com/2415eg5.png
红色,我的LinearLayouts(标题),绿色,GridLayout本身,底部的细蓝线是分隔线。
谢谢,MO
解决方案(如下所示):我必须将分频器的列权重设置为1,而不指定宽度(实际将其设置为零)。 由于我在代码中处理所有这些的特定要求,解决方案是手动实例化GridLayout.LayoutParams类并使用
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)希望这有助于将来的其他人。
I'm trying to implement a tabular layout that has a header and a bunch of rows underneath it. I've chosen the GridLayout (android.support.v7.widget.GridLayout) as there's some requirements for some elements to span multiple columns (but those are of no concern to the question).
My header cells each contain a LinearLayout with a bunch of TextViews, they're dynamically filled in code,for the sake of example, have a look at the image below. The second row should contain the divider which is a simple view, that should span my header columns (3).
The problem is the width of the divider - if I choose MATCH_PARENT, it will push the GridLayout to fill the whole remaining space to the right. The grid needs to wrap the content and center itself horizontally. It seems to me there's a conflict between the grid's layout (WRAP_CONTENT) and the divider's layout (MATCH_PARENT).
How can I fix the width of the divider without hardcoding it?
http://i61.tinypic.com/2415eg5.png
In red, my LinearLayouts (header), green, the GridLayout itself, the thin blue line at the bottom is the divider.
Thanks, MO
SOLUTION (as provided below): I had to set the column weight for the divider to 1, without specifying a width (actually setting it to zero). Because of my specific requirement to handle all of these in code, the solution was to manually instantiate the GridLayout.LayoutParams class and use
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)Hope this helps others in the future.
最满意答案
如果你将宽度设置为0dp然后给它android:layout_weight="1" (你可以给它任何你想要的重量)它应该填满所有可用的空间而不是如果我理解你正确的问题就推动你的界限
If you set the width to 0dp then give it android:layout_weight="1" (you could give it any weight you want) it should fill all the available space and not push your bounds if I understand what you are asking correctly
发布评论