layout布局实例化

实例化xml中的Layout布局在开发中经常会用到,有几种方法可以使用

1、在Activity中使用getLayoutInflater()方法

  View layout = getLayoutInflater.inflate(R.layout.item, null);

 

2、在适配器中传递上下文一般使用静态方法

  View layout = View.inflate(context, R.layout.item, null);

 

3、也可以使用

  LayoutInflater inflater = LayoutInflater.from(context);

  View layout = inflater.inflate(R.layout.item.null);

posted on 2016-10-13 10:34  语风6649  阅读(295)  评论(0编辑  收藏  举报

导航