您的位置:首页 > 其它

图片层叠并滚动效果的实现之ImageCoverFlow

2016-05-03 15:18 477 查看
需求是要有景深效果的图片轮番

<com.koolsee.player.view.imagecoverflow.CoverFlowView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coverflow"
android:layout_width="match_parent"
android:layout_height="500dp"
app:coverflowGravity="center_vertical"
app:coverflowLayoutMode="match_parent"
app:reflectionGap="10dp"
app:reflectionHeight="30%"
app:visibleImage="7" />

1.注意设置命名空间:xmlns:app="http://schemas.android.com/apk/res-auto"

2.投射效果,加强了景深效果:app:reflectionHeight="30%"

3.当前可见的图片数,app:visibleImage="7",最低不能低于3

View

CoverFlowView<MyCoverFlowAdapter> mCoverFlowView = (CoverFlowView<MyCoverFlowAdapter>) findViewById(R.id.coverflow);

adapter的数据源是一组ArrayList<Bitmap>

MyCoverFlowAdapter adapter = new MyCoverFlowAdapter(this, mResourceBitmaps);
mCoverFlowView.setAdapter(adapter);
CoverFlowView.java

private void makeChildTransformer(Bitmap child, int mid, int position, float offset) {
mChildTransformer.reset();
mReflectionTransformer.reset();

float scale = 0;
//this scale make sure that each image will be smaller than the
//previous one
if (position != mid) {
scale = 1 - Math.abs(offset) * 0.1f;//by.el 0.25
} else {
scale = 1 - Math.abs(offset) * CARD_SCALE;
}

修改缩放比例以达到图片重叠。

在drawChild方法中,给最顶上的图片加边框。通过drawBitmap在指定的位置画上去。

if(position == mid) {
//draw middle border
Rect rec = canvas.getClipBounds();
rec.bottom = wAndh[1] * 4 + 42;
rec.right = wAndh[0] * 13 / 2 + 45;
rec.top = -19;
rec.left = wAndh[0] * 5 / 2 - 18;
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
Bitmap image = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.poster_sort_focus);
canvas.drawBitmap(image, null, rec, paint);
}


“没有好于不好,只有符不符合需求。”希望对你有帮助。

开源源码详见:https://github.com/dolphinwang/ImageCoverFlow
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: