编码实现UI

  • 格式:doc
  • 大小:14.00 KB
  • 文档页数:2

编码实现UI

LinearLayout extends ViewGroup

ViewGroup extends View implements ViewParent,

ViewManager

ViewGroup是一个View容器

youtParams.FILL_PARENT -1

LinearLayout linearLayout = new LinearLayout(this);

linearLayout.setOrientation(LinearLayout.VERTICAL);

TextView textView = new TextView(this);

textView.setText(R.string.hi);

youtParams textViewParams = new

youtParams(youtParams.FILL_PARENT, youtParams.WRAP_CONTENT);

linearLayout.addView(textView, textViewParams);

View view = getUI();

linearLayout.addView(view);

youtParams layoutParams = new

youtParams(youtParams.FILL_PARENT, youtParams.FILL_PARENT);

setContentView(linearLayout, layoutParams);

布局填充服务:LayoutInflater

Private View getUI()

{

LayoutInflater inflater =

(LayoutInflater)getSystemService(YOUT_INFLATER_SERVICE);

return Inflater.inflate(yout.文件名, null);//生成的VIEW挂接的父元素

}