在实现数字的3d翻转效果一文中,我们实现了数字的翻转,本文我们利用类似的方法实现一个带3D翻转功能的ImageView。
FlipImageView可以使得一个ImageView点击之后自动翻转切换外观,它的这个特性可以让他代替传统的ToggleButton控件。
FlipImageView 内部已经包含了用于实现翻转动画的FlipAnimator,同时将点击事件的监听者设为自己,因此你只需如下运用FlipImageView 就能得到一个带点击翻转动画的ToggleButton控件:
xmlns:fiv="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/YOUR_DEFAULT_DRAWABLE"
fiv:flipDrawable="@drawable/YOUR_FLIPPED_DRAWABLE"
fiv:flipDuration="YOUR_DURATION_IN_MS"
fiv:flipInterpolator="@android:anim/YOUR_INTERPOLATOR"
fiv:flipRotations="none|x|y|z"
fiv:isAnimated="true|false"
fiv:isFlipped="true|false"/>
其中和ImageView不同的是需要制定两个图片资源文件,一个是正面的一个是反面的。
android:src="@drawable/YOUR_DEFAULT_DRAWABLE"正面。
fiv:flipDrawable="@drawable/YOUR_FLIPPED_DRAWABLE"反面。
最美壁纸应用中单张壁纸视图与网格视图之间的切换按钮就是用FlipImageView 实现的。