Layout Inflater 에 대해 서

안 드 로 이 드 를 공부 한 지 3 개 월 이 넘 었 습 니 다. BaseAdapter, RecyclerView 에서 매번 Layout Inflater 라 는 물건 이 있 었 습 니 다. 그리고 저 는 블 로 그 를 찾 아 봤 습 니 다. 즉, findview ById 와 같은 것 입 니 다. 저 는 예전 에 이 두 가지 가 어떻게 실현 되 었 는 지 자세히 생각해 보 았 습 니 다. cirl + click 은 들 어 갔 습 니 다.
이 블 로 그 를 다 쓴 후에 아주 좋 은 것 을 보 았 습 니 다. 이것 은 링크 입 니 다.          http://blog.csdn.net/guolin_blog/article/details/12921889   이 블 로그 들 은 나 로 하여 금 꽤 많은 수익 을 얻 게 한다.
@Nullable
public View findViewById(@IdRes int id) {
    return getWindow().findViewById(id);
}
@Nullable
public View findViewById(@IdRes int id) {
    return getDecorView().findViewById(id);
}
@Nullable
public final View findViewById(@IdRes int id) {
    if (id < 0) {
        return null;
    }
    return findViewTraversal(id);
}
protected View findViewTraversal(@IdRes int id) {
    if (id == mID) {
        return this;
    }
    return null;
}
       window,    view,    xml     id   id         (  ...         ,           )
  ,        LayoutInflater ~            , high     ~
     :  from       service
public static LayoutInflater from(Context context) {
    LayoutInflater LayoutInflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (LayoutInflater == null) {
        throw new AssertionError("LayoutInflater not found.");
    }
    return LayoutInflater;
}
       LayoutInflater   ,   :
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) {
    final Resources res = getContext().getResources();
    if (DEBUG) {
        Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("
                + Integer.toHexString(resource) + ")");
    }

    final XmlResourceParser parser = res.getLayout(resource);
    try {
        return inflate(parser, root, attachToRoot);
    } finally {
        parser.close();
    }
}
debug    ,     ,    XmlResourceParser  ,   xml      view  ,        ,      xml,      xml,          ,         ,       view ,       ?         ?    Mainactivity OncreateView, ?  =。=  dispatch fragment ,     Oncreate,  setContentView()    layout,     ,             resources  ,  ~     ,  layout     ~~


좋은 웹페이지 즐겨찾기