`
uz31415926
  • 浏览: 7193 次
社区版块
存档分类
最新评论

有关layoutinflater的详解

阅读更多
package cn.csdn.activity;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;

public class TabHostActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
TabHost tabhost = this.getTabHost();

/**
* LayoutInflater这个类的作用类似于findViewById(),
* 不同点:
*     LayoutInflater是用来找layout下xml布局文件的,而且它会实例化
*     findViewById()是找具体xml布局文件下的具体widget控件,比如:Button按钮
*
*
*
* inflate就相当于将一个xml中定义的布局找出来.   
* 因为如果在一个Activity文件里直接用findViewById()这个方法的话,
* 那么它所对应的是setConentView()中调用的那个layout里的组件.   
* 因此如果在同样的Activity里用到别的layout的话,
*     而且你还要设置这个layout里的组件(比如:ImageView,TextView)上的内容,
*     那么你就必须用inflate()先将这个layout找出来, 然后再用这个layout对象去找到它上面的组件
*     然后进行一系列的操作
*    
*     inflate()方法中参数:
*       1.想要用的布局文件的id
*       2.持有选项卡的内容,获取FrameLayout
*       3.true:将此处解析的xml文件做为根视图View
*/
LayoutInflater.from(this).inflate(R.layout.tabhost_layout,
tabhost.getTabContentView(), true);


/**在这里添加的时候:
*       1.必须指定 tab 的内容,必须为 id, 即:setContent(R.id.text)
*       2.必须设置tab 上的文字或图片  , 即:setIndicator("已接电话")
*       3.返回一个 TabHost.TabSpec 对象,其参数用于标识一个 tab 的 tag,即:newTabSpec("tab1")
*/
tabhost.addTab(tabhost.newTabSpec("tab1").setIndicator("已接电话")
.setContent(R.id.text));

tabhost.addTab(tabhost.newTabSpec("tab2").setIndicator("呼出电话",
getResources().getDrawable(R.drawable.ic_launcher))
.setContent(R.id.text));

tabhost.addTab(tabhost.newTabSpec("tab3").setIndicator("未接电话")
.setContent(R.id.text));
}
}
分享到:
评论

相关推荐

    LayoutInflater详解

    LayoutInflater详解 里面有详细的操作哦

    Android布局加载之LayoutInflater示例详解

    主要介绍了Android布局加载之LayoutInflater的相关资料,文中介绍的非常详细,对大家具有一定的参考借鉴价值,需要的朋友们下面来一起看看吧。

    Android开发中LayoutInflater用法详解

    本文实例讲述了Android开发中LayoutInflater用法。分享给大家供大家参考,具体如下: 在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。不同点是LayoutInflater是用来找res/layout/...

    Android LayoutInflater加载布局详解及实例代码

    Android LayoutInflater加载布局详解 对于有一定Android开发经验的同学来说,一定使用过LayoutInflater.inflater()来加载布局文件,但并不一定去深究过它的原理,比如 1.LayoutInflater为什么可以加载layout文件? ...

    Android LayoutInflater.inflate()详解及分析

    Android LayoutInflater.inflate()详解 深入理解LayoutInflater.inflate() 由于我们很容易习惯公式化的预置代码,有时我们会忽略很优雅的细节。LayoutInflater以及它在Fragment的onCreateView()中填充View的方式...

    Android中使用LayoutInflater要注意的一些坑

    LayoutInflater类在我们日常开发中经常会用到,最近在使用中就遇到了一些问题,所有下面这篇文章主要给大家总结了关于Android中使用LayoutInflater要注意的一些坑,希望通过这篇能让大家避免走一些弯路,需要的朋友...

    Android LayoutInflater.inflate源码分析

    主要介绍了Android LayoutInflater.inflate源码分析的相关资料,需要的朋友可以参考下

    Android getViewById和getLayoutInflater().inflate()的详解及比较

    Android getViewById和getLayoutInflater().inflate()的详解及比较  由于本人刚刚学习Android 对于getViewById和getLayoutInflater().inflate()的方法该如何使用不知如何分别,这里就上网查下资料整理下,大家可以...

    详解Android PopupWindow怎么合理控制弹出位置(showAtLocation)

    说到PopupWindow,应该都会有种...View contentView = LayoutInflater.from(context).inflate(layoutId, null); final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutP

    Android ListView里控件添加监听方法的实例详解

    Android ListView里控件添加监听方法的实例详解  关于ListView,算是android中比较常见的控件,在ListView我们通常需要一个模板,这个模板指的不是住模块,而是配置显示在ListView里面的东西,今天做项目的时候发现...

    android之SeekBar控件用法详解

    MainActivity.java ... import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app....import android.view.LayoutInflater; import android.view.M

    Android实现在列表List中显示半透明小窗体效果的控件用法详解

    本文实例讲述了Android实现在列表List中显示半透明小窗体效果的控件用法。分享给大家供大家参考,具体如下: Android 在列表List中显示半透明...import android.view.LayoutInflater; import android.view.View; import

    Android简易电话拨号器实例详解

    安卓开发简易电话拨号器,具体内容如下 我是基于安卓4.2.2开发的,下面是我写的MainActivity.java代码: ... import android.support.v7.app.ActionBarActivity;...import android.view.LayoutInflater; impo

    Android中Fragment的加载方式与数据通信详解

    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) inflater用于绑定Fragment的布局文件,同时将该布局转换成View对象并返回;container为Fragment的UI所在的父容器。...

Global site tag (gtag.js) - Google Analytics