- 浏览: 676283 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
Hippyqq:
谢谢很有用,
java中遍历MAP的几种方法 -
XSoftlab:
超详细。。。Java map 详解 - 用法、遍历、排序、常用 ...
java中遍历MAP的几种方法 -
bobo22:
importnet.sf.fmj.ui.application ...
java来调用电脑视频摄像头拍照进行截图 -
qq981378640:
#include <stdio.h>
int ...
c语言中unsigned类型和普通类型间的转换 -
qq981378640:
楼主你这样有点复杂了,直接这样写更好更方便
#include ...
c语言中unsigned类型和普通类型间的转换
在实际开发种LayoutInflater这个类还是非常有用的,它的作用类似于 findViewById(),
不同点是LayoutInflater是用来找layout下xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。
为了让大家容易理解我做了一个简单的Demo,主布局main.xml里有一个TextView和一个Button,当点击Button,出现 Dialog,而这个Dialog的布局方式是我们在layout目录下定义的custom_dialog.xml文件(里面左右分布,左边 ImageView,右边TextView)。
我将详细的说明Demo的实现过程:
1、新建一个 Android工程,我们命名为LayoutInflaterDemo.
2、修改main.xml布局,里面主要在 原来基础上增加了一个Button.代码如下:
view plaincopy to clipboardprint?
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ShowCustomDialog"
/>
</LinearLayout>
3.定义对话框的布局方式,我们在layout目录下,新建一个名为 custom_dialog.xml文件具体代码如下:
view plaincopy to clipboardprint?
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
4.修改主程序LayouInflaterDemo.java代码如下:
view plaincopy to clipboardprint?
package com.android.tutor;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class LayoutInflaterDemo extends Activity implements
OnClickListener {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
showCustomDialog();
}
public void showCustomDialog()
{
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = LayoutInflaterDemo.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();
}
}
5、最后执行之,点击Button,将得到上述效果。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ghd2000/archive/2010/05/11/5579930.aspx
不同点是LayoutInflater是用来找layout下xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。
为了让大家容易理解我做了一个简单的Demo,主布局main.xml里有一个TextView和一个Button,当点击Button,出现 Dialog,而这个Dialog的布局方式是我们在layout目录下定义的custom_dialog.xml文件(里面左右分布,左边 ImageView,右边TextView)。
我将详细的说明Demo的实现过程:
1、新建一个 Android工程,我们命名为LayoutInflaterDemo.
2、修改main.xml布局,里面主要在 原来基础上增加了一个Button.代码如下:
view plaincopy to clipboardprint?
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ShowCustomDialog"
/>
</LinearLayout>
3.定义对话框的布局方式,我们在layout目录下,新建一个名为 custom_dialog.xml文件具体代码如下:
view plaincopy to clipboardprint?
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
4.修改主程序LayouInflaterDemo.java代码如下:
view plaincopy to clipboardprint?
package com.android.tutor;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class LayoutInflaterDemo extends Activity implements
OnClickListener {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
showCustomDialog();
}
public void showCustomDialog()
{
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = LayoutInflaterDemo.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();
}
}
5、最后执行之,点击Button,将得到上述效果。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ghd2000/archive/2010/05/11/5579930.aspx
发表评论
-
android应用 获取本地指定类型文件 的两种最优方法
2013-04-07 16:29 14063刚因为项目有需求,需求移动应用获取本地文件有下面两个 第一个 ... -
android 滚动条
2011-01-17 14:05 2050在ListView中添加属性: android:scrollb ... -
Android虚拟机大屏幕设置(开发平板电脑程序)
2010-08-31 10:33 2890如果使用android进行大屏幕开发,比如开发基于androi ... -
adb shell下使用命令行删除android系统中指定文件和文件夹
2010-08-25 13:07 26261记录一下命令: tools>adb remount t ... -
Android permission 访问权限大全
2010-07-30 23:03 1115androidmanifest.xml中声明相关权限请求, 完 ... -
android实现底部菜单栏
2010-07-29 15:56 7081android程序,许多时候需要菜单栏显示在底部或顶部,但是没 ... -
Android ExpandableListActivity 学习笔记
2010-07-27 21:33 3363An activity that displays an ex ... -
[转]android animation的应用实例
2010-07-20 23:13 1823此文件名为myanimation.xml 位于 res/ani ... -
Android入门第八篇之GridView(九宫图)
2010-07-15 17:32 2471GridView更是实现九宫图的首选!本文就是介绍如何使用Gr ... -
Android入门第五篇之TableLayout (二)//生成10行,8列的表格
2010-07-15 14:02 4152TableLayout添加数据(9宫图也可以用TableLay ... -
Android工具之Hierarchy Viewer--分析应用程序UI布局
2010-07-14 23:37 3612Android SDK提供的Hierarchy Viewer工 ... -
apk打包
2010-07-14 23:27 10344什么是apk文件 APK是Android Package Ki ... -
Android Intent的几种用法全面总结
2010-07-14 18:05 1154Intent, 用法 Intent应该算是Android中特有 ... -
进度条(ProgressBar)拖动条(SeekBar)android
2010-07-12 17:28 16738本文源自http://www.cnblogs.com/Terr ... -
TextView 在xml文件中的解释 android
2010-07-11 19:27 6838包位置:android.widget.TextView X ... -
Activity的跳转与传值
2010-07-05 16:54 3164Activity跳转与传值,主要是通过Intent类来连接多个 ... -
android:属性 layout_alignParentRight android:paddingRight
2010-07-03 22:59 11498android:layout_alignParentRight ... -
android模拟器输入中文
2010-06-29 16:50 2767首先:在设置里,选区域和文本,里面把谷歌拼音输入法复选上,就o ... -
Android Map开发基础知识学习笔记
2010-06-29 11:14 3400注册 Android 地图 API 密钥 运行:keyto ... -
Android MapView 申请apiKey
2010-06-29 11:01 12751. 首先先要获取你的debug keystore位置: 打开 ...
相关推荐
Android 中LayoutInflater的使用
主要介绍了Android LayoutInflater分析的相关资料,需要的朋友可以参考下
LayoutInflater Layout 与 Inflater[扩充]两个单词的合并,可以理解为:当前Activity 布局的扩充.
android中LayoutInflater的使用.pdf
LayoutInflater类在我们日常开发中经常会用到,最近在使用中就遇到了一些问题,所有下面这篇文章主要给大家总结了关于Android中使用LayoutInflater要注意的一些坑,希望通过这篇能让大家避免走一些弯路,需要的朋友...
NULL 博文链接:https://yufeng-zhu.iteye.com/blog/1676207
android inflate demo,方便新手使用,下载导入android studio就可直接运行,简单明了的展现inflate不同参数的区别
测试:Android 中LayoutInflater的使用 注意:Aj_04是用了调用另外一个界面,要注意调用的方法, 还一定还要在AndroidManifest.xml 中加上呢句:<activity android:name="LayoutInflaterDemo"></activity>
主要介绍了Android开发实现自定义Toast、LayoutInflater使用其他布局,涉及Android自定义Toast与界面布局相关操作技巧,需要的朋友可以参考下
在android中,LayoutInflater有点类似于Activity的findViewById(id),不同的是LayoutInflater是用来找layout下的xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。...
通过LayoutInflater.Factory实现主题切换功能,详见:http://blog.csdn.net/llew2011
Android 中LayoutInflater(布局加载器)之实战篇 博客的Demo 博客地址: http://blog.csdn.net/l540675759/article/details/78112989 两种方式实现小红书的引导页: (1)自定义View (2)自定义LayoutInflater....
关于Android的LayoutInflater的使用!
主要介绍了Android 中LayoutInflater.inflate()方法的介绍的相关资料,希望通过本文大家能掌握这部分内容,需要的朋友可以参考下
对于有一定Android开发经验的同学来说,一定使用过LayoutInflater.inflater()来加载布局文件,但并不一定去深究过它的原理,比如 1.LayoutInflater为什么可以加载layout文件? 2.加载layout文件之后,又是怎么变成供...
Android高手进阶教程之----Android 中LayoutInflater的使用! .doc Android高手进阶教程之----Android 中MenuInflater的使用(布局定义菜单)! .doc Android高手进阶教程之----Android 中Preferences的使用! .doc ...