手工编写UI
将res中的layout目录下的main.xml给删除掉
效果图:
完整代码:
public class DemoActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//setContentView(R.layout.main);//手工编写UI布局LinearLayout ll = new LinearLayout(this);//竖直方式ll.setOrientation(LinearLayout.VERTICAL);//宽高LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);ll.setLayoutParams(params);//文本显示框TextView tv = new TextView(this);tv.setText(R.string.hello);ll.addView(tv, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);//文本框EditText et = new EditText(this);ll.addView(et, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);setContentView(ll);}}