2012-02-29 5 views
0
public void responsePost(Editable editable) 
    { 
     TableLayout chatbox = (TableLayout)findViewById(R.id.chatbox); 
     TableRow tr1 = new TableRow(this); 
     tr1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
     TextView textview = new TextView(this); 
     textview.setText(editable); 
     // textview.getTextColors(R.color.) 
     textview.setTextColor(Color.YELLOW); 

     tr1.addView(textview); 
     chatbox.addView(tr1, new TableLayout.LayoutParams(
     LayoutParams.FILL_PARENT, 
     LayoutParams.WRAP_CONTENT)); 

      textview.setGravity(Gravity.RIGHT);  
    } 

どうすればいいですか?それだけではない?私はsetGravity(Gravity.RIGHT)を使用しましたが、うまくいきませんでした。TableLayout Android Javaは完全に正しく設定されていますか?

There is a picture of what it is doing.

答えて

0

私はもう少し詳細を必要とする、私はあなたのレイアウトを複製することができませんでした、あなたはあなたのメインのレイアウトに何を持っているか、あなたは活動のためのonCreateにどのようなコードを持っているのですか?

必要なのは、伸縮性に列を設定することです:

chatbox.setColumnStretchable(1, true); 

あなたは1つの余分の行を必要とする、完全なコードは可能性があり、たとえば、ブランク

TextView col1 = new TextView(this); 
col1.setText(""); 
tr1.addView(col1); 

それを残す:

public class So extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button button = (Button) findViewById(R.id.button); 

     button.setOnClickListener(new View.OnClickListener() { 
      // anonymous inner class 
      public void onClick(View view) { 
       EditText editText1 = (EditText) findViewById(R.id.edit_text); 
       Editable editable = editText1.getText(); 
       responsePost(editable); 
       editText1.setText(""); 
      } 
     }); 
    } 

    public void responsePost(Editable editable) { 
     TableLayout chatbox = (TableLayout) findViewById(R.id.chatbox); 
     TableRow tr1 = new TableRow(this); 
     // add these lines here 
     TextView col1 = new TextView(this); 
     col1.setText(""); 
     tr1.addView(col1); 
     TextView textview = new TextView(this); 
     textview.setGravity(Gravity.RIGHT); 
     textview.setText(editable); 
     textview.setTextColor(Color.YELLOW); 
     tr1.addView(textview); 
     // and this line 
     chatbox.setColumnStretchable(1, true); 
     chatbox.addView(tr1, new TableLayout.LayoutParams(
       LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    } 
} 
+0

[tablelayoutチュートリアル](http://developer.android.coまた、[relativeLayoutチュートリアル](http://developer.android.com/resources/tutorials/views/hello-relativelayout.html)もあります。 –

+0

マーク、そこには2つのものが描画され、左側には1つ、右側にはもう1つあるので、Javaコードで必要です。 – user1239315

+0

私はうまくいけば、[look](http://i40.tinypic.com/vvq4p.png)を取って答えてくれます。 –

関連する問題