当前位置: 代码迷 >> Android >> 2013.12.04 (七)——— android SlidingMenu之CustomAnimation
  详细解决方案

2013.12.04 (七)——— android SlidingMenu之CustomAnimation

热度:71   发布时间:2016-04-28 07:12:35.0
2013.12.04 (7)——— android SlidingMenu之CustomAnimation
2013.12.04 (7)——— android SlidingMenu之CustomAnimation

这个有3个例子,主要是介绍侧边栏显示时候的动画

public class CustomScaleAnimation extends CustomAnimation {	public CustomScaleAnimation() {		super(R.string.anim_scale, new CanvasTransformer() {			@Override			public void transformCanvas(Canvas canvas, float percentOpen) {				canvas.scale(percentOpen, 1, 0, 0);			}					});	}}



package com.jeremyfeinstein.slidingmenu.example.anim;import android.graphics.Canvas;import android.view.animation.Interpolator;import com.jeremyfeinstein.slidingmenu.example.R;import com.jeremyfeinstein.slidingmenu.example.R.string;import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.CanvasTransformer;public class CustomSlideAnimation extends CustomAnimation {		private static Interpolator interp = new Interpolator() {		@Override		public float getInterpolation(float t) {			t -= 1.0f;			return t * t * t + 1.0f;		}			};	public CustomSlideAnimation() {		// see the class CustomAnimation for how to attach 		// the CanvasTransformer to the SlidingMenu		super(R.string.anim_slide, new CanvasTransformer() {			@Override			public void transformCanvas(Canvas canvas, float percentOpen) {				System.out.println(canvas.getHeight()*(1-interp.getInterpolation(percentOpen)));				canvas.translate(0, canvas.getHeight()*(1-interp.getInterpolation(percentOpen)));			}					});	}}


package com.jeremyfeinstein.slidingmenu.example.anim;import android.graphics.Canvas;import com.jeremyfeinstein.slidingmenu.example.R;import com.jeremyfeinstein.slidingmenu.example.R.string;import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.CanvasTransformer;public class CustomZoomAnimation extends CustomAnimation {	public CustomZoomAnimation() {		// see the class CustomAnimation for how to attach 		// the CanvasTransformer to the SlidingMenu		super(R.string.anim_zoom, new CanvasTransformer() {			@Override			public void transformCanvas(Canvas canvas, float percentOpen) {				float scale = (float) (percentOpen*0.25 + 0.75);				canvas.scale(scale, scale, canvas.getWidth()/2, canvas.getHeight()/2);			}		});	}}



通过调用
sm.setBehindCanvasTransformer(mTransformer);

就可以显示自定义的动画了


  相关解决方案