欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

球体旋转Anim(主要学习点Matrix知识)

程序员文章站 2022-03-16 15:09:26
...
这点Code主要对View重写进行球体旋转:
知识点:
1.重写View
2.将Drawable资源转化为Bitmap

直接上代码(便于以后查看使用):

class MyView extends View {
private Bitmap bitmap1;
private Bitmap bitmap2;
private int digree1 = 0;
private int digree2 = 360;

public MyView(Context context) {
super(context);
setBackgroundColor(Color.WHITE);
InputStream is = getResources().openRawResource(R.drawable.cross);
bitmap1 = BitmapFactory.decodeStream(is);
is = getResources().openRawResource(R.drawable.ball);
bitmap2 = BitmapFactory.decodeStream(is);
}

@Override
protected void onDraw(Canvas canvas) {
Matrix matrix = new Matrix();
if (digree1 > 360)
digree1 = 0;
if (digree2 < 0)
digree2 = 360;
matrix.setRotate(digree1++, 160, 240);
canvas.setMatrix(matrix);
canvas.drawBitmap(bitmap1, 88, 169, null);
matrix.setRotate(digree2--, 160, 240);
canvas.setMatrix(matrix);
canvas.drawBitmap(bitmap2, 35, 115, null);
invalidate();
}

}
相关标签: 360