2011-04-12 95 views
1

這是我的代碼。在結果屏幕中,它只顯示第一個TextView。不是第二個。我有點新的Android,請給予幫助。如何通過Java代碼爲Android LinearLayout添加多個TextView(在Android中)

public class Details extends Activity { 
    protected void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 

     TextView label = new TextView(this); 
     label.setText("Moves"); 
     label.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
     label.setTextSize(20);   

     TextView label2 = new TextView(this); 
     label2.setText("Time"); 
     label2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
     label2.setTextSize(20);  

     LinearLayout ll = new LinearLayout(this); 
     ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); 
     ll.setOrientation(LinearLayout.VERTICAL);       

     ll.addView(label); 
     ll.addView(label2); 

     setContentView(ll); 
    }    
} 

回答

相關問題