这个效果网上已经很多人做出来了,只是这次需要用到,所以自己也实践了一下(这里例子我也是根据网上一些资料编写)。特意找了几张美女图片给大家养养眼,O(∩_∩)O哈!下面针对一些关键代码进行简要说明,需要做这方面东西的朋友可以看看。这篇文章是实用性文章,理论分析不多。
1、重载Gallery类
因为需要加入倒影和3D切换的效果,因此我们需要重载Gallery类,其中有两个方法我们需要重写,一个是onSizeChanged(),另外一个是getChildStaticTransformation()。下面我们看看onSizeChanged()需要做的事情。
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
//重写计算旋转的中心
mCoveflowCenter = getCenterOfCoverflow();
super.onSizeChanged(w, h, oldw, oldh);
}
上面主要做的事情就是在改变大小的时候,重新计算滑动切换时需要旋转变化的中心。下面计算图片位置时,会重新计算。
protected boolean getChildStaticTransformation(View child, Transformation trans)
{
//图像的中心点和宽度
final int childCenter = getCenterOfView(child);
final int childWidth = child.getWidth();
int rotationAngle = 0;
trans.clear();
trans.setTransformationType(Transformation.TYPE_BOTH); // alpha 和 matrix 都变换
if (childCenter == mCoveflowCenter)
{
// 正中间的childView
transformImageBitmap((ImageView) child, trans, 0);
}
else
{
// 两侧的childView
rotationAngle = (int) ( ( (float) (mCoveflowCenter - childCenter) / childWidth ) * mMaxRotationAngle );
if (Math.abs(rotationAngle) > mMaxRotationAngle)
{
rotationAngle = (rotationAngle < 0) ? -mMaxRotationAngle : mMaxRotationAngle;
}
//根据偏移角度对图片进行处理,看上去有3D的效果。
transformImageBitmap((ImageView) child, trans, rotationAngle);
}
return true;
}
本文地址:https://www.stayed.cn/item/20554
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我