图形与动画在Android中的实现

阅读更多
1、简单图形的绘制
       
        canvas.drawColor(Color.BLUE);

        Paint paint = new Paint();
        paint.setColor(Color.RED);
        canvas.drawRect(10, 10, 110, 110, paint);
        canvas.drawText("This is text", 10, 130, paint);

        RectF rf1 = new RectF(10, 130, 110, 230);
        canvas.drawArc(rf1, 0, 45, true, paint);
        canvas.drawLine(150, 10, 250, 110, paint);
        RectF rf2 = new RectF(150, 130, 250, 230);
        canvas.drawOval(rf2, paint);

2、自定义动画的播放
  Android中主要有两种动画模式,一种是tweenedanimation(渐变动画),即通过对场景的对象不断做图像变换产生动画效果;另一种是framebyframe(帧动画),即按照顺序播放事先配置好的动画帧。下面主要是渐变动画的应用。
  首先创建动画文件donghuaanim.xml:

 

    
    

    
    

    
    

    
    


  添加布局文件donghua_xml.xml:
 


    


  添加DonghuaActivity.java文件:
 
package xiao.fuyan.testapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

/**
 * Created by xiao on 2017/1/10.
 */
public class DonghuaActivity extends Activity {
    Animation animation;
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.donghua_xml);

        animation = AnimationUtils.loadAnimation(this, R.anim.donghuaanim);

        imageView = (ImageView) findViewById(R.id.imageView);
        imageView.startAnimation(animation);
    }
}

你可能感兴趣的:(android,自定义动画)