Android3D广告图片滚动控件_3D图片轮播器Demo
2014-10-21 12:36:09  By: dwtedx

Android高级图片滚动控件、3D版的图片轮播器Demo、具有超强的3D效果

程序运行效果

3D图片轮播器Demo

原理也很简单、下面一起来看看整个实现的核心代码吧

如果Bitmap对象还不存在、先使用父类的onDraw方法进行绘制

绘图时需要注意、只有当图片可见的时候才进行绘制、这样可以节省运算效率

protected void onDraw(Canvas canvas) {
	if (mBitmap == null) {
		super.onDraw(canvas);
	} else {
		if (isImageVisible()) {
			computeRotateData();
			mCamera.save();
			mCamera.translate(0.0f, 0.0f, mDeep);
			mCamera.rotateY(mRotateDegree);
			mCamera.getMatrix(mMaxtrix);
			mCamera.restore();
			mMaxtrix.preTranslate(-mDx, -getHeight() / 2);
			mMaxtrix.postTranslate(mDx, getHeight() / 2);
			canvas.drawBitmap(mBitmap, mMaxtrix, null);
		}
	}
}

在这里计算所有旋转所需要的数据

private void computeRotateData() {
	float degreePerPix = BASE_DEGREE / mWidth;
	float deepPerPix = BASE_DEEP / ((mLayoutWidth - mWidth) / 2);
	switch (mIndex) {
	case 0:
	mDx = mWidth;
	mRotateDegree = 360f - (2 * mWidth + mScrollX) * degreePerPix;
	if (mScrollX < -mWidth) {
		mDeep = 0;
	} else {
		mDeep = (mWidth + mScrollX) * deepPerPix;
	}
	break;
	case 1:
	if (mScrollX > 0) {
		mDx = mWidth;
		mRotateDegree = (360f - BASE_DEGREE) - mScrollX 
* degreePerPix;
		mDeep = mScrollX * deepPerPix;
	} else {
		if (mScrollX < -mWidth) {
			mDx = -Image3DSwitchView.IMAGE_PADDING * 2;
			mRotateDegree = (-mScrollX - mWidth) * degreePerPix;
		} else {
			mDx = mWidth;
			mRotateDegree = 360f - (mWidth + mScrollX) 
* degreePerPix;
		}
		mDeep = 0;
	}
	break;
	case 2:
	if (mScrollX > 0) {
		mDx = mWidth;
		mRotateDegree = 360f - mScrollX * degreePerPix;
		mDeep = 0;
		if (mScrollX > mWidth) {
			mDeep = (mScrollX - mWidth) * deepPerPix;
		}
	} else {
		mDx = -Image3DSwitchView.IMAGE_PADDING * 2;
		mRotateDegree = -mScrollX * degreePerPix;
		mDeep = 0;
		if (mScrollX < -mWidth) {
			mDeep = -(mWidth + mScrollX) * deepPerPix;
		}
	}
	break;
	case 3:
	if (mScrollX < 0) {
		mDx = -Image3DSwitchView.IMAGE_PADDING * 2;
		mRotateDegree = BASE_DEGREE - mScrollX 
			* degreePerPix;
		mDeep = -mScrollX * deepPerPix;
	} else {
		if (mScrollX > mWidth) {
			mDx = mWidth;
			mRotateDegree = 360f - (mScrollX - mWidth) 
				* degreePerPix;
		} else {
			mDx = -Image3DSwitchView.IMAGE_PADDING * 2;
			mRotateDegree = BASE_DEGREE - mScrollX 
				* degreePerPix;
		}
		mDeep = 0;
	}
	break;
	case 4:
	mDx = -Image3DSwitchView.IMAGE_PADDING * 2;
	mRotateDegree = (2 * mWidth - mScrollX) 
		* degreePerPix;
	if (mScrollX > mWidth) {
		mDeep = 0;
	} else {
		mDeep = (mWidth - mScrollX) * deepPerPix;
	}
	break;
	}
}

源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1kT1JwBt 密码: q6pi

若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力

想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)

或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)

如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教

为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)

感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛


快速评论


技术评论

    • 740283413@qq.com 2016-09-09 11:34:45  1 评  | 回复

      怎么只能显示出来两张图片啊?怎么显示三张?图片超过3张显示就会有问题,图片重合了


DD记账
top
+