我正在尝试根据字符串的长度创建一个gridView。
每个 textView 应显示一个字符 - 下划线 - 并假设字符串中没有空格...
我以前在 c# 中做过类似的事情- 我创建了一个包含 15 个标签的表格 View ,并根据字母的数量,将每个标签向右移动。它看起来或多或少像这样:
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 做类似的事情,但不知道如何开始...帮助...
最佳答案
关注此link 这将展示如何制作你现在想要的 GridView 。您必须创建一个方法来读取 textview 值,然后创建一个逻辑将这些单词拆分为单个字符,然后将这些字符添加到 string[] 中。希望这会有所帮助
关于android - android中动态添加textView到gridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13672250/