在Android中,我已经习惯了与XML文件的setContentView()的XML布局VS查看
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
设置布局,但你也可以设置使用查看内容的Java
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
这有不能使用布局文件的副作用。
有无论如何,我可以以编程方式设置,例如,文本值,仍然使用layout.xml文件?
嗯,我不认为你可以在一个Activity中同时应用setContentView()。 –
看到这个:http://stackoverflow.com/questions/3995215/add-and-remove-views-in-android-dynamically或http://stackoverflow.com/questions/4203506/how-can-i-add- A-的TextView至A-LinearLayout中,动态的,机器人 –