编码实现简单UI界面

核心代码:

<span style="font-size:14px;">LinearLayout linearLayout = new LinearLayout(this);
		linearLayout.setOrientation(LinearLayout.VERTICAL);
		TextView textView = new TextView(this);
		textView.setText(R.string.hello_world);
		LayoutParams textLayoutParams = new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		linearLayout.addView(textView, textLayoutParams);
		View view = getUI();
		linearLayout.addView(view);

		LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);
		setContentView(linearLayout, layoutParams);
	}

	private View getUI() {
		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		return inflater.inflate(R.layout.activity_main, null);
	}</span>


posted @ 2015-09-16 16:47  稻香鱼  阅读(122)  评论(0)    收藏  举报