在android中的tablelayout中用手指画线

时间:2017-01-29 13:06:50

标签: android android-tablelayout

我为wordsearch应用程序动态创建了textview。

这是代码:

public void createGrid(final char[][] input) {
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
    final TableLayout table = (TableLayout) findViewById(R.id.mainLayout);
    table.setTag(1);
    final Typeface font = Typeface.createFromAsset(getAssets(), "kg.ttf");
    final Typeface font2 = Typeface.createFromAsset(getAssets(), "futura.ttf");
    int i;

    for (i = 0; i < input.length; i++) {
        final LinearLayout rowLayout = new LinearLayout(this);
        rowLayout.setOrientation(LinearLayout.HORIZONTAL);
        rowLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        final TableRow row = new TableRow(this);
        row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
        row.setGravity(Gravity.CENTER_HORIZONTAL);
        row.setTag(i);

        for (int j = 0; j < input.length; j++) {
            final TextView text = new TextView(this);
            Character temp = input[i][j];
            text.setText(temp.toString());
            text.setPadding(20, 20, 20, 20);
            text.setId(j);
            text.setTextSize(txtSize);
            text.setTypeface(font);
            text.setOnTouchListener(onTouch);
            text.setGravity(Gravity.CENTER);
            row.addView(text);
        }
        table.addView(row);

    }
    table.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                TableRow row = (TableRow)table.getChildAt(i);
                case MotionEvent.ACTION_DOWN:
                    startX = motionEvent.getX();
                    startY = motionEvent.getY();
                    Log.e("DOWN", "DOWN");
                    break;
                case MotionEvent.ACTION_MOVE:
                    endX = motionEvent.getX();
                    endY = motionEvent.getY();
                    break;
                case MotionEvent.ACTION_UP:
                    endX = motionEvent.getX();
                    endY = motionEvent.getY();
                    Log.e("UP", "UP " + table.getChildCount());
                    break;
            }
            return true;

        }
    });

}

现在我想要发生的事情就是当他/她突出显示网格上的字母时,在用户的手指上TextViews上的TableLayout上画一条线。我已经搜索了几天和几周来解决这个问题,但目前还没有找到任何解决方案。

非常感谢任何帮助。

0 个答案:

没有答案