- 浏览: 319469 次
- 性别:
- 来自: 武汉
文章分类
- 全部博客 (89)
- 蜗牛/ (0)
- android_app (22)
- android_activity (6)
- android_AudioManager (1)
- android_Dialog (4)
- android_EditText (3)
- android_ListView (3)
- android-Media (5)
- android_Notification (2)
- android_ProgressBar (1)
- android_sqlite (1)
- android_Service (1)
- android_SharedPreferences (1)
- android_TitleBar (3)
- android-WebView (3)
- android_常见问题解决方案 (2)
- (J2SE)XML (1)
- (J2SE)Java I/O流 (3)
- (J2SE)Socket 网络编程 (2)
- (J2SE)Java 基础 (3)
- (J2SE)Thread 学习笔记 (4)
- android google map (1)
最新评论
-
Mfeng:
Mfeng 写道评论竟然不能删除
java 实现文件/文件夹复制、剪切、删除 -
Mfeng:
评论竟然不能删除
java 实现文件/文件夹复制、剪切、删除 -
yizhesong:
如何更改回来?
android EditText设置不可写(转) -
zhb31415926:
写点有技术含量的,纯浪费时间的文章
ListView——ArrayAdapter -
somefuture:
龙哥IT 写道setTextView(int,String)? ...
Activity传递一个或者多个对象
Inflater英文意思是膨胀,在android中应该是扩展的意思吧。
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
她可以有很多地方可以使用,如BaseAdapter的getView中,自定义Dialog中取得view中的组件widget等等。
它的用法有2种:
Java代码
或者干脆并成一句:
或者干脆并成一句:
另一种方法:
Java代码
上面2种方法本质上是一样的,看下面的源码,form()调用的就是getSystemService():
Java代码
另外getSystemService()是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
传入的Name返回的对象说明
WINDOW_SERVICE WindowManager 管理打开的窗口程序
LAYOUT_INFLATER_SERVICE LayoutInflater 取得xml里定义的view
ACTIVITY_SERVICE ActivityManager 管理应用程序的系统状态
POWER_SERVICE PowerManger 电源的服务
ALARM_SERVICE AlarmManager 闹钟的服务
NOTIFICATION_SERVICE NotificationManager 状态栏的服务
KEYGUARD_SERVICE KeyguardManager 键盘锁的服务
LOCATION_SERVICE LocationManager 位置的服务,如GPS
SEARCH_SERVICE SearchManager 搜索的服务
VEBRATOR_SERVICE Vebrator 手机震动的服务
CONNECTIVITY_SERVICE Connectivity 网络连接的服务
WIFI_SERVICE WifiManager Wi-Fi服务
TELEPHONY_SERVICE TeleponyManager 电话服务
Java代码
//基本用法
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
她可以有很多地方可以使用,如BaseAdapter的getView中,自定义Dialog中取得view中的组件widget等等。
它的用法有2种:
Java代码
LayoutInflater inflater = LayoutInflater.from(this); View view=inflater.inflate(R.layout.ID, null);
或者干脆并成一句:
View view=LayoutInflater.from(this).inflate(R.layout.ID, null); LayoutInflater inflater = LayoutInflater.from(this); View view=inflater.inflate(R.layout.ID, null);
或者干脆并成一句:
View view=LayoutInflater.from(this).inflate(R.layout.ID, null);
另一种方法:
Java代码
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view=inflater.inflate(R.layout.ID, null); LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view=inflater.inflate(R.layout.ID, null);
上面2种方法本质上是一样的,看下面的源码,form()调用的就是getSystemService():
Java代码
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; } 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; }
另外getSystemService()是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
传入的Name返回的对象说明
WINDOW_SERVICE WindowManager 管理打开的窗口程序
LAYOUT_INFLATER_SERVICE LayoutInflater 取得xml里定义的view
ACTIVITY_SERVICE ActivityManager 管理应用程序的系统状态
POWER_SERVICE PowerManger 电源的服务
ALARM_SERVICE AlarmManager 闹钟的服务
NOTIFICATION_SERVICE NotificationManager 状态栏的服务
KEYGUARD_SERVICE KeyguardManager 键盘锁的服务
LOCATION_SERVICE LocationManager 位置的服务,如GPS
SEARCH_SERVICE SearchManager 搜索的服务
VEBRATOR_SERVICE Vebrator 手机震动的服务
CONNECTIVITY_SERVICE Connectivity 网络连接的服务
WIFI_SERVICE WifiManager Wi-Fi服务
TELEPHONY_SERVICE TeleponyManager 电话服务
Java代码
//基本用法
public void showCustomDialog(){ AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = AppActivity.this; //下面俩种方法都可以 //LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog,null); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("Hello, Welcome to Mr Wei's blog!"); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.icon); builder = new AlertDialog.Builder(mContext); builder.setView(layout); alertDialog = builder.create(); alertDialog.show(); } } protected void showToast(int type) { Toast.makeText(this, "*********", Toast.LENGTH_LONG).show(); LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = li.inflate(R.layout.toast, null); Toast toast = new Toast(this); toast.setView(view); toast.setDuration(type); toast.show(); }
发表评论
-
获取android设备的 子网掩码和默认网关?
2012-08-21 17:02 1080//获取mac地址 public String getLoc ... -
Android获取本机Mac地址及IP地址的方法
2012-08-21 16:29 16051、Android 获取本机Mac 地址方法: ... -
解决:Android Android requires compiler compliance level 5.0 or 6.0. 错误
2012-05-31 09:35 1833今天将ADT更新到最新的12.0版本,重新导入以前的工程,没想 ... -
Android 应用程序获得版本号
2012-05-14 20:54 1864我们可以在AndroidManifest.xml中设置程序的 ... -
android 状态栏、标题栏、屏幕高度
2012-03-02 10:40 402051.获取状态栏高度: decorView是window中的 ... -
MotionEvent中getX()和getRawX()的区别
2011-12-01 10:55 1535先看一段代码: public class Res exten ... -
获取View在屏幕中的坐标
2011-11-30 15:21 1458final int[] location = new int[ ... -
(转)Android下Affinities和Task
2011-10-22 16:24 32141、Activity和Task task就好像是能包含很多a ... -
(转)区分Activity的四种加载模式
2011-10-22 15:49 951在多Activity开发中,有可能是自己应用之间的Activi ... -
ADB适用方法(转)
2011-10-15 14:06 1007ADB是android sdk里的一个工具, 它的主要功能有: ... -
Eclipse 常用快捷键
2011-10-10 16:38 1521比较常用的Eclipse快捷键 ... -
Activity 半透明的设置
2011-09-22 09:59 961http://norety.iteye.com/blog/64 ... -
InputStream byte互转
2011-09-21 21:41 916InputStream转byte[] private byte ... -
Android获取图片的4种方式
2011-09-21 21:32 12041. 图片放在sdcard中, Bitmap imag ... -
Android UI学习 - GridView和ImageView的使用
2011-09-21 09:16 32http://android.blog.51cto.com/2 ... -
Activity之间UI的另类"更新"
2011-09-08 18:31 23这里不讨论常见的UI更新方式,请先看以下代码: Update ... -
android中常见的回调模式
2011-09-08 10:02 1482最近做ListView网络图片的异步加载,以及下载网路MP3动 ... -
Android中悬浮窗口的实现原理和示例代码(转)
2011-08-30 11:12 960用了我一个周末的时间,个中愤懑就不说了,就这个问题,我翻遍全球 ... -
控件之-ListVew(美化ListView)
2011-08-23 21:02 21一:为ListView设置背景图片 //List ... -
横竖屏切换(转)
2011-08-15 09:07 4813摘一: 在开发游戏的时候,有些游戏是只能横屏玩的,所以手机竖立 ...
相关推荐
Android 中LayoutInflater的使用
android中LayoutInflater的使用.pdf
测试:Android 中LayoutInflater的使用 注意:Aj_04是用了调用另外一个界面,要注意调用的方法, 还一定还要在AndroidManifest.xml 中加上呢句:<activity android:name="LayoutInflaterDemo"></activity>
Android 中LayoutInflater(布局加载器)之实战篇 博客的Demo 博客地址: http://blog.csdn.net/l540675759/article/details/78112989 两种方式实现小红书的引导页: (1)自定义View (2)自定义LayoutInflater....
主要介绍了Android LayoutInflater分析的相关资料,需要的朋友可以参考下
LayoutInflater Layout 与 Inflater[扩充]两个单词的合并,可以理解为:当前Activity 布局的扩充.
NULL 博文链接:https://yufeng-zhu.iteye.com/blog/1676207
down-test-Android 获得 LayoutInflater 实例的三种方式
LayoutInflater类在我们日常开发中经常会用到,最近在使用中就遇到了一些问题,所有下面这篇文章主要给大家总结了关于Android中使用LayoutInflater要注意的一些坑,希望通过这篇能让大家避免走一些弯路,需要的朋友...
主要介绍了Android 中LayoutInflater.inflate()方法的介绍的相关资料,希望通过本文大家能掌握这部分内容,需要的朋友可以参考下
在android中,LayoutInflater有点类似于Activity的findViewById(id),不同的是LayoutInflater是用来找layout下的xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。...
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
通过LayoutInflater.Factory实现主题切换功能,详见:http://blog.csdn.net/llew2011
主要介绍了Android开发实现自定义Toast、LayoutInflater使用其他布局,涉及Android自定义Toast与界面布局相关操作技巧,需要的朋友可以参考下
关于Android的LayoutInflater的使用!
3.我们定义View的时候,如果需要在布局中使用,则必须实现带AttributeSet参数的构造方法,这又是为什么呢? 既然在这篇文章提出来,那说明这三个问题都是跟LayoutInflater脱不了干系的。在我们的分析过程中,会对...
主要介绍了Android开发之获取LayoutInflater对象的方法,结合实例形式总结分析了Android获取LayoutInflater对象的常用技巧,需要的朋友可以参考下
LayoutInflater在开发中使用频率很高,但是一直没有太知道LayoutInflater.from(context).inflate()的真正用法,今天就看看源码的流程。 首先来看from()的源码: /** * Obtains the LayoutInflater from the ...