当前位置: 首页 > news >正文

建站平台外贸婚纱网站模板素材

建站平台外贸,婚纱网站模板素材,wordpress 购物主题,怎么建企业网站前面已经讲解了换肤,换资源文件的逻辑,接下来需要讲解一下如何实现自动换肤的逻辑第一步 查看LayoutInflater源码 传送门android 换肤框架详解1-换肤逻辑基本-CSDN博客 要对自动换肤有更深的了解,这里就需要对LayoutInflater源码有所了解 …

前面已经讲解了换肤,换资源文件的逻辑,接下来需要讲解一下如何实现自动换肤的逻辑第一步

查看LayoutInflater源码

传送门android 换肤框架详解1-换肤逻辑基本-CSDN博客

要对自动换肤有更深的了解,这里就需要对LayoutInflater源码有所了解

  1. LayoutInflater源码解析

从inflate进来

    public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) {return inflate(resource, root, root != null);}
    public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) {//这里可以知道,Resources是通过getContext()拿到的,我们可以直接改变getContext()中的Resourcesfinal Resources res = getContext().getResources();if (DEBUG) {Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("+ Integer.toHexString(resource) + ")");}//尝试“预编译”路径(Android 12 以后增加的优化)// 如果系统把这个 layout 提前编译成了预置的 Java 类(precompiled layout),就直接 new 出来返回,不走传统 XML 解析。View view = tryInflatePrecompiled(resource, res, root, attachToRoot);if (view != null) {return view;}//通过 AssetManager 打开一个 XmlResourceParser,指向该 layout xml 文件XmlResourceParser parser = res.getLayout(resource);try {//解析布局return inflate(parser, root, attachToRoot);} finally {parser.close();}}

 public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) {synchronized (mConstructorArgs) {Trace.traceBegin(Trace.TRACE_TAG_VIEW, "inflate");final Context inflaterContext = mContext;final AttributeSet attrs = Xml.asAttributeSet(parser);Context lastContext = (Context) mConstructorArgs[0];mConstructorArgs[0] = inflaterContext;View result = root;try {advanceToRootNode(parser);final String name = parser.getName();//解析merge标签if (TAG_MERGE.equals(name)) {if (root == null || !attachToRoot) {throw new InflateException("<merge /> can be used only with a valid "+ "ViewGroup root and attachToRoot=true");}rInflate(parser, root, inflaterContext, attrs, false);} else {// Temp is the root view that was found in the xml//解析xml里面获取到的数据,进行创建Viewfinal View temp = createViewFromTag(root, name, inflaterContext, attrs);ViewGroup.LayoutParams params = null;if (root != null) {if (DEBUG) {System.out.println("Creating params from root: " +root);}// Create layout params that match root, if suppliedparams = root.generateLayoutParams(attrs);if (!attachToRoot) {// Set the layout params for temp if we are not// attaching. (If we are, we use addView, below)temp.setLayoutParams(params);}}if (DEBUG) {System.out.println("-----> start inflating children");}// Inflate all children under temp against its context.rInflateChildren(parser, temp, attrs, true);if (DEBUG) {System.out.println("-----> done inflating children");}// We are supposed to attach all the views we found (int temp)// to root. Do that now.//如果存在VIewGroup,添加View到View上if (root != null && attachToRoot) {root.addView(temp, params);}// Decide whether to return the root that was passed in or the// top view found in xml.if (root == null || !attachToRoot) {result = temp;}}} catch (XmlPullParserException e) {final InflateException ie = new InflateException(e.getMessage(), e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;} catch (Exception e) {final InflateException ie = new InflateException(getParserStateDescription(inflaterContext, attrs)+ ": " + e.getMessage(), e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;} finally {// Don't retain static reference on context.mConstructorArgs[0] = lastContext;mConstructorArgs[1] = null;Trace.traceEnd(Trace.TRACE_TAG_VIEW);}return result;}}

正在创建View的地方

  private View createViewFromTag(View parent, String name, Context context, AttributeSet attrs) {return createViewFromTag(parent, name, context, attrs, false);}
    View createViewFromTag(View parent, String name, Context context, AttributeSet attrs,boolean ignoreThemeAttr) {try {//通过注册回调创建,这里就是自动将资源文件布局到View上的关键,这里会通过接口回调,回调到自己创建的//监听上,在这个监听里面保存对应的参数和类,然后切换换肤的时候一键修部署到ViewView view = tryCreateView(parent, name, context, attrs);if (view == null) {final Object lastContext = mConstructorArgs[0];mConstructorArgs[0] = context;try {//没有通过监听创建View,走自己的解析方法if (-1 == name.indexOf('.')) {view = onCreateView(context, parent, name, attrs);} else {view = createView(context, name, null, attrs);}} finally {mConstructorArgs[0] = lastContext;}}return view;} catch (InflateException e) {throw e;} }
   public final View tryCreateView(@Nullable View parent, @NonNull String name,@NonNull Context context,@NonNull AttributeSet attrs) {if (name.equals(TAG_1995)) {// Let's party like it's 1995!return new BlinkLayout(context, attrs);}View view;//判断是否创建了回调类,如果创建了就走创建类的回调创建View,自动换肤的关键在这里if (mFactory2 != null) {view = mFactory2.onCreateView(parent, name, context, attrs);} else if (mFactory != null) {view = mFactory.onCreateView(name, context, attrs);} else {view = null;}if (view == null && mPrivateFactory != null) {view = mPrivateFactory.onCreateView(parent, name, context, attrs);}return view;}
  public void setFactory2(Factory2 factory) {//在View解析的时候,会先执行这里,如果有创建监听,会执行这里的创建View,我们自定义的这个类,可以不走系统的解析//方法,在自己创建的factory中进行对应解析创建,并且保存对应View在xml中的状态,在换行的时候就可以将保存的类进行//换肤处理if (mFactorySet) {throw new IllegalStateException("A factory has already been set on this LayoutInflater");}if (factory == null) {throw new NullPointerException("Given factory can not be null");}mFactorySet = true;if (mFactory == null) {mFactory = mFactory2 = factory;} else {mFactory = mFactory2 = new FactoryMerger(factory, factory, mFactory, mFactory2);}}

http://www.dtcms.com/a/480152.html

相关文章:

  • 网站建设费用报价单门户网站产品设计方案
  • 某企业电子商务网站建设标书制作图片
  • 网站主办者是谁c2c网站设计
  • 网站引导插件创建网站的网站
  • 网站制作属于什么行业淮南淮北
  • 网站教程制作中国建设招标工程网站
  • 河北省建设厅网站运行条件安卓android系统下载
  • 算命网站开发电话wordpress主题仿虎嗅
  • 网站建设费按几年摊销免费简历模板在线下载
  • VMP(虚拟化高阶)免杀技术实现原理及案例
  • paxos一致性算法(大白话+图解)
  • 【Windows10】DataGrip2025.2.3安装
  • 青岛网站建设加盟公司为什么网站要改版
  • 喀什网站建设婴儿网站模板
  • 建站神器wordpress 内容注入
  • 网站建设手机app电子商务网站的建设和维护论文
  • 焦作网站seo如何建立官方网站
  • 违法网站开发免费网站推广的方法
  • 网站开发人员介绍深圳福田高端网站建设
  • 南京网站建设推南京网站建设设计拓客app下载
  • 这几年做哪些网站能致富极速网站建设定制多少钱
  • 纵深防御——文件上传漏洞
  • 为什么就一个网站打不开广西省住房和城乡建设厅网站
  • 网站开发手机app做网站怎么返回首页
  • 怎么注册一个属于自己的网站重庆森林影评
  • 新乡市网站建设有哪些公司wordpress 文章导入
  • 没有网站如何做SEO推广有用吗c .net怎么做网站
  • 网页界面设计概念巢湖市网站建设优化
  • 大数据平台网站建设海南省住房和城乡建设厅网站电脑版
  • 星大建设集团招聘网站网站平台怎么做推广