根据英文版CarouselDemo改写了其中的部分代码,实现伪3D环形的旋转木马效果,所有条目都可被点击,非最前端条目点击后会先旋转到最前端,再执行点击事件。
源码下载地址:http://download.csdn.net/download/qby_nianjun/9530318
效果展示:
在自己项目中使用时,修改以下代码即可:
MainActivity根据逻辑自行修改,主要可修改代码
Carousel.java中设置图片,绘制阴影:

public void SetImages(TypedArray array, TypedArray names,boolean reflected) {if (names != null)if (array.length() != names.length())throw new RuntimeException("图标数量与名字不符");final int reflectionGap = 3;Drawable[] drawables = new Drawable[array.length()];int[] colors = new int[] { R.color.shape1, R.color.shape2,R.color.shape3, R.color.shape4, R.color.shape5,R.color.shape6 };mImages = new CarouselItem[array.length()];for (int i = 0; i < array.length(); i++) {drawables[i] = array.getDrawable(i);// 把gradient drawable转换为BitmapBitmap originalImage = drawableToBitmap(drawables[i]);if (reflected) {int width = originalImage.getWidth();int height = originalImage.getHeight();// 创建一个宽与原始图片一样,高为加上倒影后的高度的图Bitmap bitmapWithReflection = Bitmap.createBitmap(width,(height + height / 8 + reflectionGap),Config.ARGB_8888);// 为新图创建画布Canvas canvas = new Canvas(bitmapWithReflection);// 先画出原始图片canvas.drawBitmap(originalImage, 0, 0, null);// 新建画笔对象,颜色与图片颜色一致Paint paint = new Paint();paint.setColor(getResources().getColor(colors[i]));// 设置透明度为50paint.setAlpha(50);// 设置抗锯齿paint.setAntiAlias(true);// 画椭圆RectF oval = new RectF(width / 6, height + reflectionGap,5 * width / 6, height + height / 8 + reflectionGap);canvas.drawOval(oval, paint);originalImage = bitmapWithReflection;}CarouselItem item = new CarouselItem(mContext);item.setIndex(i);item.setImageBitmap(originalImage);if (names != null)item.setText(names.getString(i));mImages[i] = item;}}

图片是自己写的shape,修改条目图片大小,只需要修改drawable下item_shapeX.xml即可,如item_shape1.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"><solid android:color="@color/shape1"/><size android:width="80dp"android:height="80dp"/><stroke android:width="4dp"/>
</shape>

这里stroken并无实际意义,如有需要,可以自行设置不同的color;
图片的颜色与倒影的颜色一一对应,所以我在values下写了一个colors.xml,分别定义了与图片数量一致的color:

<?xml version="1.0" encoding="utf-8"?>
<resources><color name="shape1">#aaff5566</color><color name="shape2">#aa55ff66</color><color name="shape3">#aa55f6ff</color><color name="shape4">#aa553388</color><color name="shape5">#aa3f86f8</color><color name="shape6">#aaa8cece</color>
</resources>

特别要注意的是,图片与文本的数量要一致,不一致会抛出异常,在attrs中:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android"><array name="entries"><item>@drawable/item_shape1</item><item>@drawable/item_shape2</item><item>@drawable/item_shape3</item><item>@drawable/item_shape4</item><item>@drawable/item_shape5</item><item>@drawable/item_shape6</item></array><array name="names"><item>The cat</item><item>The hippo</item><item>The monkey</item><item>The mouse</item><item>The panda</item><item>The rabbit</item></array>
</resources>

最后,由于倒影和原图在同一个ImageView中,如果想要文本信息刚好在原始图片的中心,需要计算,比如,我在shape中设置图片高度为80dp,可设置字体大小为16dp,可算出当TextView的marginTop值为(80/2-16/2)=32dp,所以在条目布局文件item.xml中:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" ><ImageView
        android:id="@+id/item_image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:scaleType="fitXY"android:src="@drawable/cat" /><TextView
        android:id="@+id/item_text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="32dp"android:layout_gravity="center_horizontal"android:text=""android:textColor="#fff" /></merge>

时间仓促,临时起意,如有疏漏,请多指点!

旋转木马3D环形特效相关推荐

  1. 纯JS实现旋转木马/3d相册

    纯JavaScript实现 旋转木马/3d相册特效(鼠标拖拽旋转) 先来看看效果图 说一下实现的思路 旋转木马是通过依靠拥有景深(perspective)属性的盒子(此处盒子id起为:perspect ...

  2. 用Cocos Studio 2.3.2制作UI界面中控件不再支持运行3d动作特效

    用Cocos Studio 2.3.2制作UI界面中控件不再支持运行3d动作特效  cocos2d-x + cocos studio无疑是当下二维手游开发的利器,但是在从旧版本向新版本的升级过程中,坑 ...

  3. 2.CCGridAction(3D效果),3D反转特效,凸透镜特效,液体特效,3D翻页特效,水波纹特效,3D晃动的特效,扭曲旋转特效,波动特效,3D波动特效...

     1 类图组织 2 实例 CCSprite * spr = CCSprite::create("HelloWorld.png"); spr->setPosition(cc ...

  4. 2.CCGridAction(3D效果),3D反转特效,凸透镜特效,液体特效,3D翻页特效,水波纹特效,3D晃动的特效,扭曲旋转特效,波动特效,3D波动特效

     1 类图组织 2 实例 CCSprite * spr = CCSprite::create("HelloWorld.png"); spr->setPosition(cc ...

  5. Java三维文字特效设计_jQuery实现3D文字特效的方法

    本文实例讲述了jQuery实现3D文字特效的方法.分享给大家供大家参考.具体如下: 这款基于jQuery的3D文字特效演示,不是真正的3D,是由多个文字形成的3D效果,如果首次加载网页出错的话,请刷新 ...

  6. HTML+CSS实现菜单的3D翻转特效

    HTML+CSS实现菜单的3D翻转特效 效果图如下: HTML部分源代码如下: <!DOCTYPE html> <html lang="en"><he ...

  7. JS实现最美的3D宇宙特效

    好久没更新文章了.算下来大概有五个多月了吧.之前本人更新的比较频繁是因为疫情在家,不能出门,所以有充足的时间来更新文章.之后随着疫情越来越好转,本人就出去找工作了,毕竟本人的经济条件不允许本人闲着,哈 ...

  8. linux 关闭桌面特效,[多图] Ubuntu 中开启3D桌面特效与设置方法

    Ubuntu 8.04 (Hardy Heron) 中集成了强大3D交互界面,Ubuntu 的 3D 桌面特效给用户带来了一种全新的视觉用户.想必有很多朋友也因为看到了 Ubuntu 8.04 那炫目 ...

  9. 火遍抖音的3D旋转特效

    火遍抖音的3D旋转特效代码前端代码实现: 3d旋转特效.html 0000644 0000764 0000765 00000015444 13577153703 014745 0 ustar www ...

最新文章

  1. Linux系统JDK安装和配置
  2. 浅谈代码的执行效率(4):汇编优化
  3. hud-1495--非常可乐 VS nyoj-21--三个水杯
  4. PAT-乙级-1042 字符统计
  5. 【环境搭建000】详细图解ubuntu 上安装配置eclips
  6. J.U.C - AQS
  7. 【linux基础】cuDNN版本查询
  8. 便宜SSL证书申请平台 证书获取方案
  9. 互联网日报 | 5月7日 星期五 | 街电与搜电完成合并;IBM发布2nm芯片制程;首届中国国际消费品博览会开幕...
  10. HTML(day2)
  11. 【Spring Boot JPA】ManyToOne OneToMany学习笔记
  12. register解析
  13. html中斜体样式怎么写,css font-style字体斜体样式
  14. 红米note9 android10,红米note9pro和红米note10pro区别
  15. Codeforces 1255B Fridge Lockers
  16. 四元数绕某个轴旋转某度之后的得到的四元数+pcl使用总结
  17. 骂人的到底是些什么人
  18. 百度在线html,百度编辑器-Ueditor
  19. 在一台服务器上搭建多个网站的方法(Apache版)
  20. 计算机本科毕业生去当兵,关于本科毕业生入伍,副连级待遇

热门文章

  1. Mybatis-plus开启和关闭SQL日志打印
  2. 真实盈余管理统计数据(含代码)(2000-2021年)
  3. electron-log使用
  4. 13 惠更新的三个关于期望的定理
  5. 运动想象BCI——求对称正定矩阵的负1/2次方
  6. 魔数--咖啡宝宝(Java小彩蛋)
  7. JS实现页面跳转并对新页面进行操作
  8. 重命名文件夹显示被占用
  9. 解析las文件_LAS格式的解析与转换
  10. Unity3D教程:实现房产项目中的材质动态切换