gpt4 book ai didi

java - Android Grid布局展示

转载 作者:行者123 更新时间:2023-11-30 03:06:43 26 4
gpt4 key购买 nike

我在 Android 应用程序中使用了 GridLayout,但我遇到了显示问题,

我使用 setColumnCount 来设置 3 列,因为我必须每行添加 3 个元素,所以它应该对齐。

layout1 = new GridLayout(this);
layout1.setColumnCount(3);

//In a loop later in the code :
layout1.addView(textView1);
layout1.addView(cb);
layout1.addView(textView2);

3个项目没有对齐,但都在第一列,我不太明白这个问题。

最佳答案

为您的 subview 使用 LayoutParams

GridLayout gridLayout = new GridLayout(this);
gridLayout.setColumnCount(colCount);
gridLayout.setRowCount(rowCount);

GridLayout.LayoutParams third = new GridLayout.LayoutParams(0, 0);
textView1.setLayoutParams(third);
gridLayout.addView(textView1, third);

GridLayout.LayoutParams fourth = new GridLayout.LayoutParams(0, 1);
cb.setLayoutParams(fourth);
gridLayout.addView(cb, fourth);

GridLayout.LayoutParams fifth = new GridLayout.LayoutParams(0, 2);
textView2.setLayoutParams(fifth );
gridLayout.addView(textView2, fifth);

关于java - Android Grid布局展示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21696900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com