资源简介
实现安卓主流音乐播放器中的旋转动画效果,其中包括如何对任意形状的图片进行圆形截取,以及如何从相册和拍照中获取图片
代码片段和文件信息
package com.example.ansynctasktest;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.ImageView;
public class CircleImage extends ImageView {
private int mBorderThickness = 0;
private Context mContext;
private int defaultColor = 0xFFFFFFFF;
// 如果只有其中一个有值,则只画一个圆形边框
private int mBorderOutsideColor = 0;
private int mBorderInsideColor = 0;
// 控件默认长、宽
private int defaultWidth = 0;
private int defaultHeight = 0;
private Bitmap bitmap;
private Matrix matrix;
float degree=0;
public CircleImage(Context context) {
super(context);
mContext = context;
}
public CircleImage(Context context AttributeSet attrs) {
super(context attrs);
mContext = context;
bitmap = BitmapFactory.decodeResource(getResources() R.drawable.love);
matrix = new Matrix();
setCustomAttributes(attrs);
}
public CircleImage(Context context AttributeSet attrs int defstyle) {
super(context attrs defstyle);
mContext = context;
setCustomAttributes(attrs);
}
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0){
CircleImage.this.invalidate();
}
}
};
private void setCustomAttributes(AttributeSet attrs) {
TypedArray a = mContext.obtainstyledAttributes(attrs
R.styleable.circleView);
mBorderThickness = a.getDimensionPixelSize(
R.styleable.circleView_roundedimageview_border_thickness 0);
mBorderOutsideColor = a
.getColor(R.styleable.circleView_roundedimageview_border_outside_color
defaultColor);
mBorderInsideColor = a.getColor(
R.styleable.circleView_roundedimageview_border_inside_color defaultColor);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
this.measure(0 0);
if (drawable.getClass() == NinePa
评论
共有 条评论