如何在android中以编程方式移动飞机图片?

如何在android中以编程方式移动飞机图片?,android,animation,imageview,Android,Animation,Imageview,我知道如何在android中使用此源代码时移动图像 这个代码是完美的,在圆内移动图像视图,但我想在圆内移动飞机图片,我想它应该看起来像飞机的真实运动。有人能帮我吗公共类动画视图扩展视图{ public class AnimationView extends View { Paint paint; Bitmap bm; int bm_offsetX, bm_offsetY; Path animPath; PathMeasure pathMeasure;

我知道如何在android中使用此源代码时移动图像 这个代码是完美的,在圆内移动图像视图,但我想在圆内移动飞机图片,我想它应该看起来像飞机的真实运动。有人能帮我吗

公共类动画视图扩展视图{
public class AnimationView extends View {

    Paint paint;
    Bitmap bm;
    int bm_offsetX, bm_offsetY;
    Path animPath;
    PathMeasure pathMeasure;
    float pathLength;
    float step;   //distance each step
    float distance;  //distance moved
    float[] pos;
    float[] tan;
    Matrix matrix;

    public AnimationView(Context context) {
        super(context);
        initMyView();
    }

    public AnimationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initMyView();
    }

    public AnimationView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initMyView();
    }

    public void initMyView(){
        paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(4);
        paint.setStyle(Paint.Style.STROKE);
        DashPathEffect dashPath = new DashPathEffect(new float[]{6,6}, (float)2.0);

        paint.setPathEffect(dashPath);

        bm = BitmapFactory.decodeResource(getResources(), R.drawable.airplane);
        bm_offsetX = bm.getWidth()/2;
        bm_offsetY = bm.getHeight()/2;

        animPath = new Path();
        animPath.addCircle(600, 600, 500, Path.Direction.CW);
        animPath.close();

        pathMeasure = new PathMeasure(animPath, false);
        pathLength = pathMeasure.getLength();

        step = 1;
        distance = 0;
        pos = new float[2];
        tan = new float[2];

        matrix = new Matrix();
    }

    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawPath(animPath, paint);

        if(distance < pathLength){
            pathMeasure.getPosTan(distance, pos, tan);

            matrix.reset();
            float degrees = (float)(Math.atan2(tan[0], tan[1])*0.0/Math.PI);
            matrix.postRotate(degrees, bm_offsetX, bm_offsetY);
            matrix.postTranslate(pos[0]-bm_offsetX, pos[1]-bm_offsetY);

            canvas.drawBitmap(bm, matrix, null);

            distance += step;
        }else{
            distance = 0;
        }

        invalidate();
    }
油漆; 位图bm; int bm_offsetX,bm_offsetY; 路径;路径; 路径测量路径测量; 浮动路径长度; 浮动步长;//每个步长的距离 浮动距离;//移动的距离 浮动[]pos; 浮法[]谭; 矩阵; 公共动画视图(上下文){ 超级(上下文); initMyView(); } 公共动画视图(上下文、属性集属性){ 超级(上下文,attrs); initMyView(); } 公共动画视图(上下文、属性集属性、int defStyleAttr){ super(上下文、attrs、defStyleAttr); initMyView(); } public void initMyView(){ 油漆=新油漆(); 油漆。设置颜色(颜色。蓝色); 油漆。设置行程宽度(4); 绘制.设置样式(绘制.样式.笔划); DashPathEffect dashPath=新DashPathEffect(新浮点[]{6,6},(浮点)2.0); paint.setPathEffect(dashPath); bm=BitmapFactory.decodeResource(getResources(),R.drawable.framework); bm_offsetX=bm.getWidth()/2; bm_offsetY=bm.getHeight()/2; animPath=新路径(); animPath.addCircle(600600500,Path.Direction.CW); animPath.close(); pathMeasure=新的pathMeasure(animPath,false); pathLength=pathMeasure.getLength(); 步骤=1; 距离=0; pos=新浮动[2]; tan=新浮点数[2]; 矩阵=新矩阵(); } @凌驾 受保护的void onDraw(画布){ 画布.绘制路径(动画路径,绘制); if(距离<路径长度){ getPosTan(距离、位置、tan); matrix.reset(); 浮点度数=(浮点)(数学atan2(tan[0],tan[1])*0.0/Math.PI); 矩阵。后旋转(度、bm_偏移量x、bm_偏移量); 后翻译(pos[0]-bm_offsetX,pos[1]-bm_offsetY); drawBitmap(bm、矩阵、空); 距离+=步长; }否则{ 距离=0; } 使无效(); }
在圆圈中移动图像视图和在圆圈中移动飞机图片有什么区别?
飞机的真实运动看起来如何?
尚不清楚。
在圆圈中移动图像视图和在圆圈中移动飞机图片有什么区别。
:/您可以应用圆圈如果你所说的真实运动是指一些特殊效果,那么你可以使用gifimage@UsmanRana听着,先生,我有一张飞机的照片,我可以把它画成圆圈,但问题是它不符合圆圈的形状,你知道它应该像真实的飞机画成圆圈,但这里只有飞机画成圆圈,它没有在这种情况下,飞机在圆周运动时也应该转弯,对吗?但你有2D图像,而不是unity games那样的3D模型。为了更好地查看,你可以使用svg或gif图像。