setContentView()与LayoutInflater.inflate()作用

@Override
 protected void onCreate(Bundle savedInstanceState) {
  try{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.jzxt_main);
   loadView();
   if(BS.client == null) new LoginValidat().execute();
  }catch (Exception e) {
   BS.pb.outErrorLog(this, "oncreat", e);
  }
  
 }

上述代码中setContentView(R.layout.jzxt_main)作用就是相当于LayoutInflater.inflate()的作用:

即,将布局文件转换为可操作的view对象(实例),才能引用view类的一系列方法,从而达到对布局文件xml中的各个组件实例化(简单的findViewById()方法)

时间: 2024-08-03 08:21:19

setContentView()与LayoutInflater.inflate()作用的相关文章

【android】LayoutInflater.inflate方法的详解及xml根元素的布局参数不起作用的问题

一.首先看带三个参数的inflate方法: public View inflate (int resource, ViewGroup root, boolean attachToRoot) 1.如果root不为null,且attachToRoot为TRUE,则会在加载的布局文件的最外层再嵌套一层root布局,这时候xml根元素的布局参数当然会起作用. 2.如果root不为null,且attachToRoot为false,则不会在加载的布局文件的最外层再嵌套一层root布局,这个root只会用于为

LayoutInflater的作用

LayoutInflater的作用是导入界面,说白了就是查找layout中的.xml界面并导入.如下: public class MainActitivity extends Acticity{ TextView textView; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); textVi

6、Android之LayoutInflater.inflate()

LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个布局文件: findViewById则是从布局文件中查找一个控件: 一.获取LayoutInflater对象有三种方法 LayoutInflater inflater=LayoutInflater.from(context); LayoutInflater inflater=getLayoutInf

Android LayoutInflater.inflate的使用及源码分析

欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/61913656 本文出自:[余志强的博客] 在实际开发中我们常常需要inflate要给布局然后添加到某个布局容器里面去, 要把xml布局文件转成一个View对象 需要使用LayoutInflater.inflate方法. 在开发中常常使用如下几种方式: inflater.inflate(layoutId, null); inflater.inflate(layoutI

android LayoutInflater.inflate详解

LayoutInflater概述 从XML文件中实例化一个布局成对应的View类, 它从来不会直接使用, 而是使用getLayoutInflater()或者getSystemService(String)来获得一个对应当前context的标准LayoutInflater 实例. 例如: 1 2 3 LayoutInflater inflater = (LayoutInflater)context.getSystemService       (Context.LAYOUT_INFLATER_SE

android LayoutInflater.inflate()的参数介绍

LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个布局文件: findViewById则是从布局文件中查找一个控件: 一.获取LayoutInflater对象有三种方法 LayoutInflater inflater=LayoutInflater.from(context); LayoutInflater inflater=getLayoutInf

Android LayoutInflater.inflate使用上的问题解惑

最近在在使用LayoutInflater.inflate方法时遇到了一些问题,以前没有仔细看过此类的使用方法,故将其记录下来,方便日后查阅. 相信大家都知道LayoutInflater.inflate是在android开发遇到的一些使用频率是非常高的方法,如果使用不好的,就会出现一些奇怪的问题. 一个例子如下: 1,一个主布局文件如下 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

Android应用setContentView与LayoutInflater加载解析机制源码分析

[工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处,尊重分享成果] 1 背景 其实之所以要说这个话题有几个原因: 理解xml等控件是咋被显示的原理,通常大家写代码都是直接在onCreate里setContentView就完事,没怎么关注其实现原理. 前面分析<Android触摸屏事件派发机制详解与源码分析三(Activity篇)>时提到了一些关于布局嵌套的问题,当时没有深入解释. 所以接下来主要分析的就是View或者ViewGroup对象是如何添加至应用程

LayoutInflater inflate LayoutParams 简介

LayoutInflater简介 LayoutInflater就是布局填充器,作用是将xml布局文件转化为View对象. 可以通过以下两种方式获取LayoutInflater,其实他们是完全一样的 LayoutInflater layoutInflater = LayoutInflater.from(context); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER