2012-08-02 76 views
1
LinearLayout.LayoutParams labellayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
    LinearLayout.LayoutParams textlayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT); 
    for(int i=0 ;i < 2;i++){ 
     TextView label = new TextView(this); 
     EditText text = new EditText(this); 

     labellayoutParams.setMargins(40, 30, 30 , 0); 
     textlayoutParams.setMargins(60, 30, 30 , 0); 
     text.setHint("Type Here"); 
     label.setText("some text"); 

     ll.addView(label); 
     ll.addView(text); 
    } 
    this.setContentView(ll); 

上面的代碼將顯示輸出滯留在addview

注:讓我們sometext假設爲TextView的和_ __ _爲EditText上

some text ____________ some text _____________ 

,但我想要一個這樣的輸出

some text ____________ 

some text ____________ 

我試圖setOrientation(LinearLayout.VERTICAL),但它給喜歡這個

some text 

_____________ 

some text 

_____________ 

回答

1

你的LinearLayout名爲LL應該有它的財產「機器人:定向」設置爲「垂直」

0

你必須設置的LinearLayout定向ll.setorientation(VERTICAL)要獲得textviews垂直排列

+0

我試過太多,但它命令所有在垂直這樣 一些文字 _______________ 一些文字 __________________ – Anand 2012-08-02 11:45:29

0

如果妳調整佈局的垂直方向,這將正常工作....

+0

我試過了,但它給不同的輸出 – Anand 2012-08-02 11:53:21

0

嘗試使用不同佈局......我認爲它不能被水平和垂直地添加到單個佈局中(在LinearLayout中)。您[R試圖在這裏做吧..