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);
}
}
我試過了。但它仍然不工作:( – dinesh707 2011-04-12 22:28:44
發表你現在擁有的 – JoxTraex 2011-04-12 22:38:22
我更新了代碼在新問題 – dinesh707 2011-04-12 22:42:42