0

我有一个相对布局,其中 textviews 排列在一列以上。单击屏幕时,有一个“弹出屏幕”或“输入屏幕”(不知道如何调用),其中我定义了“从”和“到”的时间,学校班级的名称等。它将计算它需要从该输入合并哪些文本视图。合并的文本视图必须像一个更大的文本视图。有可能做这样的事情吗?

谢谢前面的回答。

像这样的东西:http: //i.stack.imgur.com/r1o8D.png

4

1 回答 1

0

我有一个想法,您可以尝试创建一个自定义视图来绘制它而不是使用视图。

在新类中扩展 View 类并覆盖 onDraw 方法。

//variables
Paint paint[]; //Set up these paints with the colors you need
int rowWidth, int colHeight;
void onDraw(Canvas c){
    for(int i=0;i<noOfRows;i++){
       for(int j=0;j<noOfColumns;j++){
            if(cellRequired(i,j)){
              //cellRequired will be whatever logic you have to check if cell is required

                int rectHeight=colHeight; //Now the Rect Height changes whether the cell
                                         //  below is in use or not.
                for(int k=i;k<noOfRows;k++){                         
                     //This loop will run through the rows and see if merging is required
                      if(cellRequired(i,k))
                             rectHeight+=colHeight; //Merge Cell
                      else 
                              break; //If not required at any point break loop
                 }
                 //Draw Rectangle background
                 c.drawRect(i*rowWidth +i, j*colHeight +j, rowWidth, rectHeight, backPaint);
                 //Draw Text
                 canvas.drawText("Text",i*rowWidth +i, j*colHeight +j, paint[requiredPaint]);
                 //I added the plus i and plus j so there'd be a gap in the rectangles
                 // Then it will be a border
            }         
       }
    }
}

关于自定义控件的 Android 文档

Android:自定义视图创建教程

如何制作类似于上面的自定义视图

http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html

通过这些,然后通过上面的代码。希望它应该向您展示如何实现它。

于 2012-12-06T15:06:26.757 回答