本文主要是介绍图片左右滚动控件(带倒影)——重写Gallery,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天在网上找了些资料,做了一个图片左右滚动的Demo,类似幻灯片播放,同时,图片带倒影效果,运行效果如下图:
实现方式是重写Gallery,使用自定义的Gallery来实现这一效果,工程一共三个文件,一个Activity,一个自定义的Gallery,还有就是一个适配器ImageAdapter,直接上代码:
ScrollGallery.java
public class ScrollGallery extends Gallery {private Camera mCamera = new Camera();//左右图片倾斜的角度private int mMaxRotationAngle = 60;//背景区域大小private int mMaxZoom = -380;private int mCoveflowCenter;public ScrollGallery(Context context) {super(context);this.setStaticTransformationsEnabled(true);}public ScrollGallery(Context context, AttributeSet attrs) {super(context, attrs);this.setStaticTransformationsEnabled(true);}public ScrollGallery(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);this.setStaticTransformationsEnabled(true);}public int getMaxRotationAngle() {return mMaxRotationAngle;}public void setMaxRotationAngle(int maxRotationAngle) {mMaxRotationAngle = maxRotationAngle;}public int getMaxZoom() {return mMaxZoom;}public void setMaxZoom(int maxZoom) {mMaxZoom = maxZoom;}private int getCenterOfCoverflow() {return (getWidth() - getPaddingLeft() - getPaddingRight()) / 2+ getPaddingLeft();}private static int getCenterOfView(View view) {return view.getLeft() + view.getWidth() / 2;}protected boolean getChildStaticT
这篇关于图片左右滚动控件(带倒影)——重写Gallery的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!