您的位置:首页 > 其它

自定义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

数据:

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>

六、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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: