Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

android - How to draw a line inside a tablelayout?

I am currently developing an android word search game. And I'm just learning Android Studio for almost a month now. I had made the ui of the game. Now my problem is the gameplay. I used a tablelayout for the textviews containing the letters for the puzzle.

Here is my createGrid() method for creating the tablelayout grid:

   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);
    }
}

What I want to do is make the tablelayout interactive by drawing a line when highlighting some letters.

I read this article that is all about the onDraw() and onTouchEvent() methods.

Now, I want to learn how to insert those codes on my program.

Or if that's impossible to do, any suggestions to help me improve this game?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...