然,看到头像点击要加滤镜效果,有个新奇 的做法是用setColorFilter();
/**
*Createdbyyxon16/4/3.
*/publicclassDiscolorImageViewextendsImageView{/**
*变暗
*/
privatefinalfloat[]SELECTED_DARK=newfloat[]
{1,0,0,0,-80,0,1,0,0,-80,0,0,1,0,-80,0,0,0,1,0};/**
*变亮
*/
privatefinalfloat[]SELECTED_BRIGHT=newfloat[]
{1,0,0,0,80,0,1,0,0,80,0,0,1,0,80,0,0,0,1,0};/**
*高对比度
*/
privatefinalfloat[]SELECTED_HDR=newfloat[]
{5,0,0,0,-250,0,5,0,0,-250,0,0,5,0,-250,0,0,0,1,0};/**
*高饱和度
*/
privatefinalfloat[]SELECTED_HSAT=newfloat[]
{(float)3,(float)-2,(float)-0.2,0,50,
-1,2,-0,0,50,
-1,-2,4,0,50,0,0,0,1,0};/**
*改变色调
*/
privatefinalfloat[]SELECTED_DISCOLOR=newfloat[]
{(float)-0.5,(float)-0.6,(float)-0.8,0,0,
(float)-0.4,(float)-0.6,(float)-0.1,0,0,
(float)-0.3,2,(float)-0.4,0,0,0,0,0,1,0};publicDiscolorImageView(Contextcontext){
super(context);this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);
}publicDiscolorImageView(Contextcontext,AttributeSetattrs){
super(context,attrs);this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);
}publicDiscolorImageView(Contextcontext,AttributeSetattrs,intdefStyle){
super(context,attrs,defStyle);this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);
}publicOnTouchListenerVIEW_TOUCH_DISCOLOR=newOnTouchListener(){
@OverridepublicbooleanonTouch(Viewv,MotionEventevent){if(event.getAction()==MotionEvent.ACTION_DOWN){
ImageViewiv=(ImageView)v;
iv.setColorFilter(newColorMatrixColorFilter(SELECTED_HDR));//iv.setColorFilter(newColorMatrixColorFilter(SELECTED_BRIGHT));
//iv.setColorFilter(newColorMatrixColorFilter(SELECTED_HDR));
//iv.setColorFilter(newColorMatrixColorFilter(SELECTED_HSAT));
//iv.setColorFilter(newColorMatrixColorFilter(SELECTED_DISCOLOR));
}elseif(event.getAction()==MotionEvent.ACTION_UP){
ImageViewiv=(ImageView)v;
iv.clearColorFilter();
mPerformClick();
}elseif(event.getAction()==MotionEvent.ACTION_CANCEL){
ImageViewiv=(ImageView)v;
iv.clearColorFilter();
}returntrue;
}
};privatevoidmPerformClick(){
DiscolorImageView.this.performClick();
}
}