在Layout xml中配置自定义View
2011-11-08 22:55
393 查看
1. Layout xml文件中的配置
main.xml
view
plainprint?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.larry.testbuild.MyListView android:id="@+id/my_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
注意在引用自定义的View类时,要写出类的全路径,即包名.类名
2. 自定义的View,这里以继承ListView为例
MyListView.java
view
plainprint?
package com.larry.testbuild
public class MyListView extends ListView {
public DishListView(Context context) {
super(context);
}
public DishListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
...
}
注意需要继承父类的两个构造函数,少一个都会造成Force close。
对于ListView这样做的好处是,不需要将Adapter的子类定义置于ListView所在的父Activity类中。增强ListView的模块化,从而降低耦合,增强复用性。
本帖转自:/article/8392293.html
main.xml
view
plainprint?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.larry.testbuild.MyListView android:id="@+id/my_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
注意在引用自定义的View类时,要写出类的全路径,即包名.类名
2. 自定义的View,这里以继承ListView为例
MyListView.java
view
plainprint?
package com.larry.testbuild
public class MyListView extends ListView {
public DishListView(Context context) {
super(context);
}
public DishListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
...
}
注意需要继承父类的两个构造函数,少一个都会造成Force close。
对于ListView这样做的好处是,不需要将Adapter的子类定义置于ListView所在的父Activity类中。增强ListView的模块化,从而降低耦合,增强复用性。
本帖转自:/article/8392293.html
相关文章推荐
- 在Layout xml中配置自定义View
- 如何在xml中配置自定义view以及使view动起来
- 自定义View冷知识之动态替换layout.xml中的View
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- Android中layout.xml文件中加载自定义的View类
- 通过自定义view替代layout.xml表示activity的界面
- 自定义的LinearLayout 使用报错 android.view.InflateException: Binary XML file line #3: Error inflating class
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- Android解析自定义属性的XML实现底部导航栏TabSelectedView,实现灵活的配置扩展
- 自定义shape的view,不用配置xml
- Android学习个人笔记1-Layout界面布局-xml,java混合模式-自定义view
- Autolayout_自定义View
- web.xml 配置404和500错误的自定义页面
- 在web.xml中配置openSessionInView的使用
- 使用tablayout报异常-android.view.InflateException: Binary XML file
- Android自定义View研究--View中的原点坐标和XML中布局自定义View时View触摸原点问题
- 【iOS】自定义collocationViewLayout实现瀑布流
- iOS UIActivityViewController自定义分享配置
- 关于web.xml配置error-page或者springmvc添加自定义异常返回画面,画面没有显示
- Android中自定义View的研究 -- 在XML中引用自定义View