编码实现简单UI界面

来源:互联网 发布:淘宝上旗舰店是真的吗 编辑:程序博客网 时间:2024/04/29 03:47

核心代码:

<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>


0 0
原创粉丝点击