android - android中动态添加textView到gridView

标签 android android-layout

我正在尝试根据字符串的长度创建一个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/

相关文章:

android - 具有 phonegap 的 Android 客户端的 Web 服务的权威签名证书或自己的证书

android - Eclipse:初始化监控线程失败:无法建立环回连接

Android解析html表格

java - 安卓 Java : Buttons and TextViews not showing up when added via Java (to existing XML layout)

android - Snackbar 和 FloatingActionButton 错误

javascript - 解析从 Android 应用程序返回的 javascript 值对象

android - 如何在不使用服务的情况下接收位置更新

android - Google Play 音乐风格 GridView

android - 在 ListView 行中模仿溢出微调器

android - Android Viewpager 中图像的连续翻转