开源项目地址:https://github.com/castorflex/FlipImageView

  本实例我没做什么改动,就是添加了注释,方便大家阅读。和之前一样,导入library和工程文件即可明白如何使用。

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:gravity="center_horizontal"> <fr.castorflex.android.flipimageview.library.FlipImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_gravity="center"
android:src="@drawable/ic_action_star_0"
app:flipDrawable="@drawable/ic_action_star_10"
app:flipDuration="5000"
app:flipInterpolator="@android:anim/bounce_interpolator"
app:flipRotations="y|x|z"
app:reverseRotation="true"/> <TextView
android:id="@+id/textview"
android:layout_marginTop="24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <Spinner
android:id="@+id/spinner"
android:layout_height="wrap_content"
android:layout_width="match_parent" /> <SeekBar
android:id="@+id/seekbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:max="5000"
android:progress="500" /> <LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"> <TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="duration:" /> <TextView
android:id="@+id/textview_duration"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="500" />
</LinearLayout> <LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:minHeight="48dp"
android:gravity="center"> <CheckBox
android:id="@+id/checkedtextview_x"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Rot. X" /> <CheckBox
android:id="@+id/checkedtextview_y"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Rot. Y"
android:checked="true"/> <CheckBox
android:id="@+id/checkedtextview_z"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Rot. Z" /> </LinearLayout> <CheckBox
android:id="@+id/checkedtextview_reverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reverse rotation" /> </LinearLayout>

SampleActivity

package fr.castorflex.android.flipimageview.sample;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView; import fr.castorflex.android.flipimageview.R;
import fr.castorflex.android.flipimageview.library.FlipImageView; public class SampleActivity extends Activity implements FlipImageView.OnFlipListener,
SeekBar.OnSeekBarChangeListener { /**
* 定义翻转的模式,用作spinner的数据
*/
private static final String[] fData = new String[]{
"Decelerate",
"Accelerate",
"AccelerateDecelerate",
"Bounce",
"Overshoot",
"AnticipateOvershoot" }; private static final Interpolator[] fInterpolators = new Interpolator[]{
new DecelerateInterpolator(),
new AccelerateInterpolator(),
new AccelerateDecelerateInterpolator(),
new BounceInterpolator(),
new OvershootInterpolator(),
new AnticipateOvershootInterpolator()
}; private SeekBar mSeekBar; private Spinner mSpinner; private TextView mTextViewDuration; private FlipImageView mFlipImageView; private CheckBox mCheckBoxX; private CheckBox mCheckBoxY; private CheckBox mCheckBoxZ; private CheckBox mCheckBoxReverse; private TextView mTextViewAnimationListener; /**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //翻转成功、翻转中的表示文字,用监听器触发
mTextViewAnimationListener = (TextView) findViewById(R.id.textview);
//将要翻转的图片
mFlipImageView = (FlipImageView) findViewById(R.id.imageview);
//设置翻转模式的spinner
mSpinner = (Spinner) findViewById(R.id.spinner);
//提示选择翻转时间的文字
mTextViewDuration = (TextView) findViewById(R.id.textview_duration);
//设置翻转时间的滑动条
mSeekBar = (SeekBar) findViewById(R.id.seekbar);
//选择翻转轴的选择框,X Y Z轴,不进行轴旋转,可以多选
mCheckBoxX = (CheckBox) findViewById(R.id.checkedtextview_x);
mCheckBoxY = (CheckBox) findViewById(R.id.checkedtextview_y);
mCheckBoxZ = (CheckBox) findViewById(R.id.checkedtextview_z);
//没设置XYZ轴翻转的情况下,此选项进行简单的缩放翻转
mCheckBoxReverse = (CheckBox) findViewById(R.id.checkedtextview_reverse); mSpinner.setAdapter(
new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, fData)); mSeekBar.setOnSeekBarChangeListener(this); mFlipImageView.setOnFlipListener(this);
} /////////////////////FLIP IMAGE VIEW/////////////////// @Override
public void onClick(FlipImageView view) {
//设置效果 mFlipImageView.setInterpolator(interpolator)
mFlipImageView.setInterpolator(fInterpolators[mSpinner.getSelectedItemPosition()]);
//设置时间,时间是毫秒
mFlipImageView.setDuration(mSeekBar.getProgress());
//设置翻转的轴、或不按轴翻转,传入的参数都是boolean型
mFlipImageView.setRotationXEnabled(mCheckBoxX.isChecked());
mFlipImageView.setRotationYEnabled(mCheckBoxY.isChecked());
mFlipImageView.setRotationZEnabled(mCheckBoxZ.isChecked());
mFlipImageView.setRotationReversed(mCheckBoxReverse.isChecked()); //下面要设置监听器了
//FlipImageView.OnFlipListener
} /* (非 Javadoc)
* @see fr.castorflex.android.flipimageview.library.FlipImageView.OnFlipListener#onFlipStart(fr.castorflex.android.flipimageview.library.FlipImageView)
* 监听器
*/
@Override
public void onFlipStart(FlipImageView view) {
//开始翻转
mTextViewAnimationListener.setText("OnFlipStart");
} /* (非 Javadoc)
* @see fr.castorflex.android.flipimageview.library.FlipImageView.OnFlipListener#onFlipEnd(fr.castorflex.android.flipimageview.library.FlipImageView)
* 监听器
*/
@Override
public void onFlipEnd(FlipImageView view) {
//翻转结束
mTextViewAnimationListener.setText("OnFlipEnd");
} ////////////////////////SEEK BAR///////////////////////// @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mTextViewDuration.setText("" + progress);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) {
} @Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}

源码下载:http://download.csdn.net/detail/shark0017/7710153

用开源项目FlipImageView实现图片的翻转效果的更多相关文章

  1. css3图片3D翻转效果

    点击图片看翻转效果 html结构 <div class="flip"> <div class="front"> <img src= ...

  2. 基于jQuery遮罩图片hover翻转效果

    基于jQuery遮罩图片hover翻转效果.这是一款基于jQuery+css3实现的鼠标经过遮罩图片翻转特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div cla ...

  3. 用开源项目CropImage实现图片的裁剪(不推荐)

       之前介绍过一个截图的办法(http://www.cnblogs.com/tianzhijiexian/p/3900241.html),这里再分享个开源项目.它也是截图,但是效果不是很好,首先还是 ...

  4. 用开源项目PhotoView实现图片的双指缩放和双击放大缩小

    项目地址:https://github.com/chrisbanes/PhotoView 用开源项目有个好处,一是实现简单,二是bug少.那么我们就来说下这个项目能够实现的效果: 1.单个图片的双指缩 ...

  5. CSS3之图片3D翻转效果(网页效果--每日一更)

    今天,带来的是纯CSS3的效果--图片3D翻转. 请看效果:亲,请点击这里 这个效果主要还是运用了CSS3的transform变形属性,与上个效果不同的是,这次并不是动画,所以没有采用animatio ...

  6. 图片触及翻转效果 css3

    实现图片由左向右飞入回到最初设定位置 ,鼠标浮上去旋转显示另一张图片效果: html: <!DOCTYPE HTML> <html> <head> <meta ...

  7. Android 开源项目分类汇总(转)

    Android 开源项目分类汇总(转) ## 第一部分 个性化控件(View)主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Galler ...

  8. HTML和CSS实现图片翻转效果

    实现图片翻转,首先来分析一下我们希望实现的是怎样的翻转效果?又该如何去实现呢? 一.希望实现的效果 页面上的图片在光标悬停在上面的时候会发生翻转效果,翻转过后显示出背面的说明文字. 鼠标没有悬停在上面 ...

  9. Android 图片加载[常见开源项目汇总]

    该文主要是讲一下目前有哪些使用比较多的 图片加载开源项目,并简单介绍该如果使用 以及各开源项目之间有什么区别, 我们该如何去选择适合的开源项目应用到我们的项目中? 一.Android-Universa ...

随机推荐

  1. Error:Makefile:452: target 'config' given more than once in the same rule

    在解压的 linux2.6.15 文件夹下 make menuconfig 的时候出现下面的错误: Makefile:452: target 'config' given more than once ...

  2. 第一届CCF软件能力认证

    1.相反数 问题描述 有 N 个非零且各不相同的整数.请你编一个程序求出它们中有多少对相反数(a 和 -a 为一对相反数). 输入格式 第一行包含一个正整数 N.(1 ≤ N ≤ 500). 第二行为 ...

  3. (转阮一峰)深入理解OAuth 2.0

    OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛应用,目前的版本是2.0版. 本文对OAuth 2.0的设计思路和运行流程,做一个简明通俗的解释,主要参考材料为R ...

  4. Caffe训练AlexNet网络模型——问题三

    caffe 进行自己的imageNet训练分类:loss一直是87.3365,accuracy一直是0 解决方法: http://blog.csdn.net/jkfdqjjy/article/deta ...

  5. vue组件之间通信传值

    原文链接:https://blog.csdn.net/lander_xiong/article/details/79018737 我认为这位博主的这篇文章写的非常详细,通俗易懂, 我们这次的vue项目 ...

  6. JDBC之批处理

    JDBC之批处理 现在有这么一个需求,要求把2000条记录插入表中,如果使用java代码来操作,我们可以使用Statement或者PreparedStatement来实现,通过循环来把SQL语句一条又 ...

  7. 【BZOJ 1005】 1005: [HNOI2008]明明的烦恼 (prufer数列+高精度)

    1005: [HNOI2008]明明的烦恼 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4981  Solved: 1941 Description ...

  8. bzoj 4036 集合幂级数

    集合幂级数其实就是一种集合到数的映射,并且我们针对集合的一些操作(or  xor and specil or )为这种映射定义运算.其中一些东西可以通过某些手段将其复杂度降低. orz vfk /** ...

  9. Android命令(更新……)

    1.通过命令行安装包 语法:adb install -r  apk包 例子:adb install -r D:\android\android-sdk-windows\platform-tools\L ...

  10. CentOS 7安装tunctl

    cat << EOF > /etc/yum.repos.d/nux-misc.repo [nux-misc] name=Nux Misc baseurl=http://li.nux. ...