[android]手工编写UI

Android 4.0

手工编写UI
     将res中的layout目录下的main.xml给删除掉

效果图:
      

完整代码:
public class DemoActivity extends Activity {

    @Override
    public 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);
    }
}