图片翻页效果。



效果如上图


//声明Page类对象
	private Page page = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //实例化Page对象
        page = new Page(this);
        //显示page
        setContentView(page);
    }






package com.test;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.BitmapDrawable;
//import android.util.Log;
import android.view.View;


public class Page extends View implements Runnable {
	
	private static final int width = 480;
	private static final int height = 320;
	private int x = 0;
	private int y = height;
	
	//声明Paint对象
	private Paint paint1 = null;
	private Paint paint3 = null;
	//声明Path对象
	private Path path = null;
	//构建Matrix对象 
	Matrix matrix = new Matrix();
	
	//创建图片对象
	private Bitmap image1 = null;
	private Bitmap image2 = null;
	private Bitmap image4 = null;
	private Bitmap image5 = null;
	private Bitmap image3 = null;

	public Page(Context context) {
		super(context);
		paint1 = new Paint();
		paint3 = new Paint();
		
		image1 = ((BitmapDrawable)getResources().getDrawable(R.drawable.image1)).getBitmap();
		image2 = ((BitmapDrawable)getResources().getDrawable(R.drawable.image2)).getBitmap();
		//将image2反转
		image3 = Bitmap.createScaledBitmap(image2, -width, height, true);
		//设置第三张图片透明度
		paint3.setAlpha(150);
	
		//开启线程
		new Thread(this).start();
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		for (int i = 0; i < 10; i++) {
		//画最底下那张图
		Rect rect = new Rect(0, 0, width, height);
		canvas.drawBitmap(image1, null, rect, paint1);
		//设定path
		path = new Path();
		path.moveTo(width, 0);
		path.lineTo(width, height);
		path.lineTo(x, height);
		if(y>0) {
			path.lineTo(0, y);
			path.lineTo(0, 0);
		}
		else path.lineTo(x-height, 0);
		path.close();
		//裁剪出一块区域
		canvas.clipPath(path, Region.Op.REPLACE);
		//画出第二张图
		canvas.drawBitmap(image2, 0, 0, paint1);
		//Log.v("jinwei", ""+x + ":" + y);
		
		//画出第三张图,首先是平移和旋转
		matrix.reset();
		matrix.postTranslate(x-width, y-height);
		matrix.postRotate(270, x, y);
		canvas.drawBitmap(image3, matrix, paint3);
		}
	}

	@Override
	public void run() {
		while(!Thread.currentThread().isInterrupted() && x<=(width+height)) {
			try {
				if(y==height)
					Thread.sleep(1000);
				else Thread.sleep(50);
			} catch (InterruptedException e) {
				Thread.currentThread().interrupt();
			}
			x += 10;
			y -= 10;
			postInvalidate();
		}
	}
	
	
}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值