Api Demo - .graphics(2)
//关键字:Drawable 添加矢量动画 package com.example.android.apis.graphics; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.graphics.*; import android.graphics.drawable.*; import android.view.animation.*; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; public class AnimateDrawables extends GraphicsActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this)); } private static class SampleView extends View { private AnimateDrawable mDrawable; public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); Drawable dr = context.getResources().getDrawable(R.drawable.beach); dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());//是缩放不是截取 Animation an = new TranslateAnimation(0, 100, 0, 200); an.setDuration(2000); an.setRepeatCount(-1); an.initialize(10, 10, 10, 10);//传值可以任意。但是必须做次步骤 mDrawable = new AnimateDrawable(dr, an);//Drawable 添加动画 an.startNow(); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); mDrawable.draw(canvas); invalidate(); } } }
相关推荐
大地飞鸿 2020-11-12
星星有所不知 2020-10-12
jinxiutong 2020-07-26
MIKUScallion 2020-07-05
songfens 2020-07-05
songfens 2020-06-11
songfens 2020-06-08
northwindx 2020-05-31
northwindx 2020-05-31
northwindx 2020-05-27
northwindx 2020-05-25
MIKUScallion 2020-05-25
jinxiutong 2020-05-10
xdyangxiaoromg 2020-05-10
大地飞鸿 2020-05-06
northwindx 2020-04-25