编码实现简单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>
日拱一卒百无有尽,功不唐捐终入海
浙公网安备 33010602011771号