使用单元格

时间:2016-05-24 11:29:08

标签: android android-layout android-studio fonts android-gridview

我想在gridview上绘制字母(基本上是作为led板)。我试图从用户获取输入字符串并在gridview中绘制该字符串,如下所示。 gridview大小由两个6x5板固定。我需要以这样的方式绘制该字符串,使得框架看起来从右向左移动(基本上每2秒间隔刷新一次布局)。我无法理解如何通过输入字符串在gridview单元格上绘制这些字母。任何类型的引用和链接也适用于我。

快照链接:http://imgur.com/pb3lfCv

在下次更新时,列应该向左移动一列,在这种情况下,我们应该能够看到第一个字母的4/5和完整的第二个字母,第三个字母才会从右侧开始输入..

间隔2秒后的快照:http://imgur.com/Ue8y0OC

间隔2秒后的快照:http://imgur.com/mebRsuM

2 个答案:

答案 0 :(得分:1)

也许在2秒的间隔内做类似的事情:

int i = currentCharacter;
//code for left char
switch(str.charAt(i)){
 case "A":
 //Code for the letter A
break;
 case "B":
 //Code for the letter B
break;
...
}
//code for right char
switch(str.charAt(i+1)){
 case "A":
 //Code for the letter A
break;
 case "B":
 //Code for the letter B
break;
...
}
currentCharacter++;

你可以给出彩色立方体ID,只需定义颜色即可。所以例如字母'S'就像:

cube1.setBackgroundColor(Color.RED);
cube2.setBackgroundColor(Color.GREEN);
cube3.setBackgroundColor(Color.GREEN);
cube4.setBackgroundColor(Color.GREEN);
cube5.setBackgroundColor(Color.RED);
cube6.setBackgroundColor(Color.RED);
cube7.setBackgroundColor(Color.GREEN);
cube8.setBackgroundColor(Color.RED);
cube9.setBackgroundColor(Color.RED);
cube10.setBackgroundColor(Color.RED);
//and so one ...

如果网格是这样的:

01 02 03 04 05

06 07 08 09 10

11 12 13 14 15 ...

这只是一个想法,但它可以帮助你:D

答案 1 :(得分:0)

嘿,我得到了上面的解决方案 - 我自己开发了一个类,它具有一个以字符作为输入并以6 * 6矩阵和放大器返回其显示模式的功能。长度字段用于确保显示的宽度。使用此jar为整个字符串创建一个2-d数组,并使用一端的屏幕大小窗口遍历该数组。这是该类的代码:

public class TextPat {
    public int length;
    public int[][] flag;
    public void getFlag(char data) {
        switch (data){
            case 'A':
            {
             length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'B':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

            case 'C':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'D':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

                case 'E':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;
            case 'F':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case 'G':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'H':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;
            case 'I':
            {
                length=2;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case 'J':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'K':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,1,0,0,0},
                        {1,1,0,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'L':
            {
                length=4;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0}};
            }break;
            case 'M':
            {
                length=6;
                flag=new int[][]{
                        {1,1,0,1,1,0},
                        {1,1,1,1,1,0},
                        {1,0,1,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'N':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,1,0,0,1,0},
                        {1,1,1,0,1,0},
                        {1,0,1,1,1,0},
                        {1,0,0,1,1,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'O':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'P':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'Q':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0},
                        {0,0,0,0,1,0}};
            }break;

            case 'R':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'S':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'T':
            {
                length=4;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0}};
            }break;

            case 'U':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'V':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'W':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,1,0,1,0},
                        {1,1,1,1,1,0},
                        {0,1,0,1,0,0}};
            }break;

            case 'X':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'Y':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'Z':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'a':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'b':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

            case 'c':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'd':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,1,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'e':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'f':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'g':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'h':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'i':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'j':
            {
                length=4;
                flag=new int[][]{
                        {0,0,1,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {1,0,1,0,0,0},
                        {0,1,0,0,0,0}};
            }break;

            case 'k':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,1,0,0,0},
                        {1,1,0,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0}};
            }break;
            case 'l':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'm':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,1,0,1,0},
                        {1,0,1,0,1,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'n':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'o':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'p':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'q':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,1,0}};
            }break;

            case 'r':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,1,1,0,0},
                        {1,1,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 's':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;
            case 't':
            {
                length=5;
                flag=new int[][]{
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {1,1,1,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'u':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'v':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'w':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,1,0,1,0},
                        {0,1,0,1,0,0}};
            }break;
            case 'x':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'y':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'z':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case '.':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case ',':
            {
                length=3;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '!':
            {
                length=2;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '?':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,1,1,0,0},
                        {0,0,1,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case '1':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {1,1,1,1,1,0}};
            }break;
            case '2':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,0,0,1,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,1,0}};
            }break;

            case '3':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,1,1,0,0},
                        {0,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '4':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,1,0,0},
                        {0,0,1,1,0,0},
                        {0,1,0,1,0,0},
                        {1,1,1,1,1,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0}};
            }break;

            case '5':
            {
                length=6;
                flag=new int[][]{
                        {1,1,1,1,1,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {0,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '6':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,1,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '7':
            {
                length=6;
                flag=new int[][]{
                        {1,1,1,1,1,0},
                        {0,0,0,0,1,0},
                        {0,0,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '8':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '9':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,1,0},
                        {0,0,0,0,1,0},
                        {1,1,1,1,0,0}};
            }break;
            case '0':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            default:
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0}};
            }break;
        }
    }
}