Android:代码设置UI
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android:代码设置UI相关的知识,希望对你有一定的参考价值。
private void addViewByCode(){ View subView = new View(context); subView.setBackgroundColor(Color.RED); //subView的宽高 int subViewwidth = 700; int subViewHeight = 300; RelativeLayout.LayoutParams relLayoutParams = new RelativeLayout.LayoutParams(subViewwidth, subViewHeight); //addRule默认是ALIGN_PARENT_LEFT+ALIGN_PARENT_TOP relLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); relLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); int left = 300; int top = 200; relLayoutParams.setMargins(left, top, 0, 0); root_RelativeLayout.addView(subView, relLayoutParams); }
以上是关于Android:代码设置UI的主要内容,如果未能解决你的问题,请参考以下文章