颈椎病的自我治疗_颈椎病_枕头_什么枕头好_什么样的枕头好

Android LayoutFlater 的使用

  一、 使用LayoutFlater目的

  将layout转成view, 用于别的组件显示

  二、 LayoutFlater的获取

  1. 通过LayoutFlater静态方法

  Java代码

  layoutInflater = LayoutInflater.from(context);

  layoutInflater = LayoutInflater.from(context);

  2. 通过Context:

  Java代码

  LayoutInflater LayoutInflater =

  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

  LayoutInflater LayoutInflater =

  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

  两者是一样的。

  三、 LayoutFlater的使用:

  常用的LayoutFlater方法:

  Java代码

  public View inflate(int resource, ViewGroup root, boolean attachToRoot)

  public View inflate(int resource, ViewGroup root, boolean attachToRoot)

  参数:

  resource ID for an XML layout resource to load (e.g., R.layout.main_page)

  root Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)

  attachToRoot Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.

  其实是通过:

  Java代码

  public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)

  public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)

  上面的那个是通过这个:

  Java代码

  XmlResourceParser parser = getContext().getResources().getLayout(resource);

标签:AndroidLayoutFlater
分类:Android开发| 发布:admin| 查看: | 发表时间:2012-1-3
原创文章如转载,请注明:转载自枕头网--枕头品牌|保健枕头|决明子枕头|枕头高度 http://www.hownot.cn/
本文链接:http://www.hownot.cn/webdesign/Android-LayoutFlater-20120103.html

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Design By eso | Login | Power By Z-Blog 1.8 Arwen Build 90619.