自定义view的简单使用
2015-05-30 11:37
441 查看
一、自定义view的使用
1、创建view子类
2、在布局文件中以view子类为标签名
二、onTouchEvent回调函数
重写onTouchEvent方法
三、xml生命属性
1、先定义View,根据需求确定想要的属性
2、到values文件夹下新建attrs.xml
3、在view的定义代码中获取这些属性
其中attrs文件在res文件夹下values文件夹下。
四、绘制路径文字
绘制文字路径:
canvas.drawPath(path, paint);
void moveTo (float x1, float y1):直线的开始点;即将直线路径的绘制点定在(x1,y1)的位置;
void lineTo (float x2, float y2):直线的结束点,又是下一次绘制直线路径的开始点;lineTo()可以一直用;
void close ():如果连续画了几条直线,但没有形成闭环,调用Close()会将路径首尾点连接起来,形成闭环;
canvas.drawTextOnPath("asddghrsthbrftge",path, 10, 20, paint);
paint.setStrokeWidth(2);//边缘线的宽度
paint.setTextSize(60);//文字大小
上面两个属性绘制文本,结合:
paint.setStyle(Style.STROKE);
五、折叠列表
控件名:ExpandableListView
数据:
控件中需要的布局:
Parent布局、child布局
Adapter:BaseExpandableListAdapter
监听:
Parent展开监听:exaLV.setOnGroupExpandListener
Parent折叠监听:exaLV.setOnGroupCollapseListener
Parent点击监听:exaLV.setOnGroupClickListener
Child点击监听:exaLV.setOnChildClickListener
改变parent的收/展图片
exaLV.setGroupIndicator()
或android:groupIndicator="@null"
六、Frame动画
1、在xml文件中设置设置图片资源和展示时间
2、布局文件中将ImageView控件的背景设置为该资源文件
3、开启动画
七、瀑布流
1、创建ScrolllView子类,且添加滑动监听
2、创建给imageview控件添加图片的方法类,其中图片在assets文件夹下imgs文件夹中
3、MainActivity类
4、布局文件中
activity.getAssets().open("imgs/"+imgName)
activity.runOnUiThread()
imgNames=getAssets().list("imgs");
// getMeasuredHeight();//测量高度
// getHeight();//显示在屏幕上的高度
// getScrollY();//滑动高度
imgvW
bitmapW、bitmapH
imgvH/imgvW=bitmapH/bitmapW
imgvH=bitmapH*imgvW/bitmapW
1、创建view子类
2、在布局文件中以view子类为标签名
二、onTouchEvent回调函数
重写onTouchEvent方法
三、xml生命属性
1、先定义View,根据需求确定想要的属性
2、到values文件夹下新建attrs.xml
3、在view的定义代码中获取这些属性
其中attrs文件在res文件夹下values文件夹下。
四、绘制路径文字
绘制文字路径:
canvas.drawPath(path, paint);
void moveTo (float x1, float y1):直线的开始点;即将直线路径的绘制点定在(x1,y1)的位置;
void lineTo (float x2, float y2):直线的结束点,又是下一次绘制直线路径的开始点;lineTo()可以一直用;
void close ():如果连续画了几条直线,但没有形成闭环,调用Close()会将路径首尾点连接起来,形成闭环;
canvas.drawTextOnPath("asddghrsthbrftge",path, 10, 20, paint);
paint.setStrokeWidth(2);//边缘线的宽度
paint.setTextSize(60);//文字大小
上面两个属性绘制文本,结合:
paint.setStyle(Style.STROKE);
五、折叠列表
控件名:ExpandableListView
数据:
String arrParent[]={"A","B","C"}; String arrChild[][]={{"awer","asdf","axcv"},{"byui","bhjk","bnm,"},{"crty","cfgh","cvbn"}}; |
Parent布局、child布局
Adapter:BaseExpandableListAdapter
监听:
Parent展开监听:exaLV.setOnGroupExpandListener
Parent折叠监听:exaLV.setOnGroupCollapseListener
Parent点击监听:exaLV.setOnGroupClickListener
Child点击监听:exaLV.setOnChildClickListener
改变parent的收/展图片
exaLV.setGroupIndicator()
或android:groupIndicator="@null"
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_expanded="true" android:drawable="@drawable/erweima"/> <item android:drawable="@drawable/adduser"></item> </selector> |
1、在xml文件中设置设置图片资源和展示时间
2、布局文件中将ImageView控件的背景设置为该资源文件
3、开启动画
七、瀑布流
1、创建ScrolllView子类,且添加滑动监听
2、创建给imageview控件添加图片的方法类,其中图片在assets文件夹下imgs文件夹中
3、MainActivity类
4、布局文件中
activity.getAssets().open("imgs/"+imgName)
activity.runOnUiThread()
imgNames=getAssets().list("imgs");
// getMeasuredHeight();//测量高度
// getHeight();//显示在屏幕上的高度
// getScrollY();//滑动高度
imgvW
bitmapW、bitmapH
imgvH/imgvW=bitmapH/bitmapW
imgvH=bitmapH*imgvW/bitmapW
相关文章推荐
- hdu 2045 不容易系列之(3)—— LELE的RPG难题(java)
- 台大机器学习听课笔记---RF 10-3 Feature Selection
- APACHE启用gzip压缩模块大幅提升网…
- LoadRunner&nbsp;11.50&nbsp;下载+安装…
- 使用QC10调用loadrunnerP11
- 使用QTP&nbsp;11批量修改QC10测试…
- 使用QC10远程启用QTP11(也可在本…
- QTP跑单独的脚本(虚拟对象)
- 性能测试思维导图(云层)
- 实例讲解虚拟机3种网络模式(桥接、…
- 【转载】Linux/Unix笔记本
- Linux&nbsp;netstat命令详解
- IIS7并发数优化
- 监控MSSQL(SQL&nbsp;Server)
- zabbix无法登录,session未记录
- mysql&nbsp;性能优化方案
- 51testing自动化测试学习第三天
- 51testing自动化测试学习第二天
- windows&nbsp;server&nbsp;2008&amp;nb…
- PHP+IIS的配置