MyException - 我的异常网
当前位置: 我的异常网 » 移动开发 » 圆球旋转Anim(主要学习点Matrix知识)

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

www.MyException.Cn,网友分享于:2012-06-30   浏览:11次
球体旋转Anim(主要学习点Matrix知识)
这点Code主要对View重写进行球体旋转:
知识点:
1.重写View
2.将Drawable资源转化为Bitmap

直接上代码(便于以后查看使用):
Java代码 
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();  
        }  
 
    } 
软件开发程序错误异常Exception Copyright © 2009-2015 MyException 版权所有