Android:将并排视图添加到tableRow

时间:2014-03-27 01:25:35

标签: android android-tablelayout

我目前正在向新的tableRow添加几个TextView和一个Button。它工作正常,但它们是垂直添加的。你怎么能并排添加它们呢?

这就是代码的样子:

public void submitAnswer(View view) {
    AlertDialog.Builder answer = new AlertDialog.Builder(this);

    answer.setTitle("Submit Question");
    answer.setMessage("Enter question: ");

    // Set an EditText view to get user input 
    final EditText input = new EditText(this);
    final TableRow tr = new TableRow(this);
    final TextView ans = new TextView(this);
    final TextView likeCount = new TextView(this);
    likeCount.setText("0");
    final Button likeButton = new Button(this);
    likeButton.setText("Like");
    answer.setView(input);

    answer.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();

            ans.setText(value);

            TableLayout tl = (TableLayout)findViewById(R.id.CSQ1answers);

            ans.setWidth(450);
            ans.setTextSize(20);

            likeButton.setTextSize(20);             
            likeCount.setTextSize(20);

            tl.addView(ans);
            tl.addView(likeButton);
            tl.addView(likeCount);
        }
    });

    answer.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });

    answer.show();

}

1 个答案:

答案 0 :(得分:1)

问题是关于TableRow tr,只是你不使用它。使用它,让我们知道它是否正常工作。感谢