球体旋转Anim(主要学习点Matrix知识)
程序员文章站
2022-03-16 15:09:26
...
这点Code主要对View重写进行球体旋转:
知识点:
1.重写View
2.将Drawable资源转化为Bitmap
直接上代码(便于以后查看使用):
知识点:
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();
}
}
上一篇: 一个Android工程师是否高级,最直观的就是看他做的UI高不高级
下一篇: 360Lib:CPP