Android 如何在表格布局中画一条线?

Android 如何在表格布局中画一条线?,android,android-studio,android-tablelayout,Android,Android Studio,Android Tablelayout,我目前正在开发一款android单词搜索游戏。我刚刚学习安卓工作室将近一个月。我制作了游戏的用户界面。现在我的问题是游戏性。我为包含拼图字母的文本视图使用了表格布局 下面是创建tablelayout网格的createGrid()方法: public void createGrid(char[][] input){ TableLayout table = (TableLayout) findViewById(R.id.mainLayout); Typeface font =

我目前正在开发一款android单词搜索游戏。我刚刚学习安卓工作室将近一个月。我制作了游戏的用户界面。现在我的问题是游戏性。我为包含拼图字母的文本视图使用了表格布局

下面是创建tablelayout网格的createGrid()方法:

   public void createGrid(char[][] input){
    TableLayout table = (TableLayout) findViewById(R.id.mainLayout);
    Typeface font = Typeface.createFromAsset(getAssets(),"kg.ttf");


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

        for(int j = 0; j < input.length; j++){
            TextView text = new TextView(this);
            Character temp = input[i][j];
            text.setText(temp.toString());
            text.setPadding(20, 20, 20, 20);
            text.setTextSize(25);
            text.setTypeface(font);
            text.setGravity(Gravity.CENTER);
            row.addView(text);
        }
        table.addView(row);
    }
}
public void createGrid(char[][]输入){
TableLayout table=(TableLayout)findViewById(R.id.mainLayout);
Typeface font=Typeface.createFromAsset(getAssets(),“kg.ttf”);
for(int i=0;i
我想做的是,在突出显示一些字母时画一条线,从而使tablelayout具有交互性

我读到的这篇文章都是关于onDraw()和onTouchEvent()方法的

现在,我想学习如何在我的程序中插入这些代码


或者,如果这是不可能做到的,有什么建议可以帮助我改进这个游戏吗?

@QBrute不知道你在说什么,先生?从哪一点到哪一点,你想划出那条线?@marmor从触摸开始到手指停止运动的地方。我读过这篇文章,但它的特点是一个gridviewwell,这似乎是这个问题的重复,你使用的是
表格布局
,而在这个问题上,它是一个
GridView
,只需使用
setOnTouchListener
的部分,即
table.setOnTouchListener(…)
并且您可能希望使用xml布局将您的
表格布局
放入
框架布局
中,就像在他的代码中一样