Android 中LayoutInflater的使用
2011-03-24 16:54
447 查看
LayoutInflater的使用,在实际开发种LayoutInflater这个类还是非常有用的,它的作用类似于 findViewById(),不同点是:
LayoutInflater是用来找layout下xml布局文件,并且实例化!
findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。
为了让大家容易理解我做了一个简单的Demo,主布局main.xml里有一个TextView和一个Button,当点击Button,出现 Dialog,而这个Dialog的布局方式是我们在layout目录下定义的custom_dialog.xml文件(里面左右分布,左边 ImageView,右边TextView)。
效果图如下:
.placeslist_linearlayout.xml
[/b]
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.placeslist_linearlayout);
linearLayout.addView(place_type_text);
这是可运行的,这上面的xml中,LinearLayout不再是Layout的代表,而只是一个普通的View。
LayoutInflater是用来找layout下xml布局文件,并且实例化!
findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。
为了让大家容易理解我做了一个简单的Demo,主布局main.xml里有一个TextView和一个Button,当点击Button,出现 Dialog,而这个Dialog的布局方式是我们在layout目录下定义的custom_dialog.xml文件(里面左右分布,左边 ImageView,右边TextView)。
效果图如下:
.placeslist_linearlayout.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/placeslist_linearlayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </ScrollView>
[/b]
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.placeslist_linearlayout);
linearLayout.addView(place_type_text);
这是可运行的,这上面的xml中,LinearLayout不再是Layout的代表,而只是一个普通的View。
相关文章推荐
- Android 中LayoutInflater的使用!
- 【Android动态布局】之【LayoutInflater的使用】
- Android笔记之使用LayoutInflater创建View
- Android 中LayoutInflater的使用!
- Android中LayoutInflater的使用
- 【Android 界面效果23】LayoutInflater作用及使用
- Android 中LayoutInflater的使用(转)
- Android 中LayoutInflater的使用
- android LayoutInflater使用
- Android高手进阶教程(五)之----Android 中LayoutInflater的使用!
- Android------LayoutInflater作用及使用
- 【android】关于使用ViewPager和LayoutInflater的出现问题
- android中LayoutInflater的使用
- Android 中LayoutInflater的使用!
- Android LayoutInflater的使用
- Android 中LayoutInflater的使用
- Android学习之LayoutInflater类的使用
- Android 中LayoutInflater的使用
- Android中LayoutInflater的使用
- android之LayoutInflater的获取与使用