动态添加文本视图';android中的gridView

动态添加文本视图';android中的gridView,android,android-layout,Android,Android Layout,我正在尝试根据字符串的长度创建gridView 每个文本视图都应该显示一个字符-下划线-并假设字符串中没有空格 我以前在c语言中也做过类似的事情#- 我在一个包含15个标签的桌面视图中放置了一个框架,并根据字母的数量将每个标签向右移动。它看起来或多或少像这样: public void setLetters(String str) { tableLayoutPanel1.Visible = false; int x = revah(s

我正在尝试根据字符串的长度创建gridView

每个文本视图都应该显示一个字符-下划线-并假设字符串中没有空格

我以前在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;

    } 
public void setLetters(String str)
{
tableLayoutPanel1.Visible=false;
int x=revah(str);//revah返回字符串中的字母数
int yy=x/2;
整数计数=0;

如果(count您可以使用GridView(通过活动膨胀)创建布局,并使用textview创建其他布局。之后,您必须实现一个适配器,用字符串(在方法getView中)填充GridView(ArrayAdapter)。方法getCount()将确定项的数量。此方法在ArrayAdapter类中,您必须重写它们。请检查此处:

遵循以下步骤
这将展示如何创建网格视图,这是您现在想要的。您必须创建一个方法来读取您的textview值,然后创建一个逻辑,将这些单词拆分为单个字符,然后将这些字符添加到字符串[]中。希望这会有所帮助

比如,如果textview值是helloworld,那么您希望在gridview中显示helloworld,比如h l o w o r l d?我收到了吗?嗯……不完全是……但是如果您能告诉我如何做,我会理解:)你没有看到任何使你的代码更简单的方法吗?:)是的……但我只是为了它的工作,而不是为了真正的工作。:P