我正在尝试根据字符串的长度创建一个 gridView。
每个 textView 都应该显示一个字符 - 一个下划线 - 并假设字符串中没有空格......
我以前在 c# 中做过类似的事情——我创建了一个包含 15 个标签的表格视图,并根据字母的数量,将每个标签向右移动。它看起来或多或少是这样的:
public void setLetters(String str)
{
tableLayoutPanel1.Visible = false;
int x = revah(str); //revah returns the number of letters in the string
int yy = x / 2;
int count = 0;
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl0, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl1, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl2, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl3, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl4, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl5, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl6, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl7, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl8, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl9, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl10, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl11, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl12, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl13, yy);
count++;
}
if (count <= x)
{
tableLayoutPanel1.SetColumn(lbl14, yy);
count++;
}
tableLayoutPanel1.Visible = true;
}
我希望在android中做类似的事情,使用gridView,但不知道如何开始......帮助......