android-LayoutInfalter 获view

但是如果在非activity中如何对控件布局设置操作了,这就需要LayoutInflater动态加载。
 
 
第一种方法
 
LayoutInflater inflater = (LayoutInflater)      Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
View view= =inflater.inflate(R.layout.custom_dialog,null);     
TextView text = (TextView)      view.findViewById(R.id.text);     
 
第二种方法
LayoutInflater inflater = LayoutInflater.from(this);     
View view=inflater.inflate(R.layout.ID, null); 
或者直接
View view=LayoutInflater.from(this).inflate(R.layout.ID, null); 
 
第三种 方法
 
View view = View.inflate(this, R.layout.dialog_layout, null);
posted @ 2013-12-06 12:01  可惜不是你  阅读(378)  评论(0编辑  收藏  举报