开源项目地址: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. day12--python操作mysql

        本篇对于Python操作MySQL主要使用两种方式:     1.原生模块 pymsql(http://www.cnblogs.com/wupeiqi/articles/5713330.htm ...

  2. scrollIntoView将指定元素定位到浏览器顶部,底部,中间

    var element = document.getElementById("box"); element.scrollIntoView();//顶部 element.scroll ...

  3. 让HTML5来为你定位(转)

    add by zhj: HTML5的地理定位返回的应该都是GPS坐标,即WGS-84坐标,参见Map Types - Google Maps JavaScript API v3 本文使用的是Chrom ...

  4. 【python学习-4】可复用函数与模块

    1.自定义函数 自定义函数格式如下: def <函数名> (参数列表): <函数语句> return <返回值> #!/usr/bin/python # 定义函数, ...

  5. linux安装project lemon测评机

    (写下备用) 机子:xubuntu 16.04 LTS 1.下载lemon github地址:https://github.com/Sojiv/Project_lemon 这里download zip ...

  6. 4951: [Wf2017]Money for Nothing 决策单调性 分治

    Bzoj4951:决策单调性 分治 国际惯例题面:一句话题面:供应商出货日期为Ei,售价为Pi:用户收购截止日期为Si,收购价格为Gi.我们要求max((Si-Ej)*(Gi-Pj)).显然如果我们把 ...

  7. Codeforces.810D.Glad to see you!(交互 二分)

    题目链接 \(Description\) 有一个大小为\(k\)的集合\(S\),元素两两不同且在\([1,n]\)内.你可以询问不超过\(60\)次,每次询问你给出\(x,y\),交互库会返回\(\ ...

  8. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  9. NOIP 2013 转圈游戏

    [题目描述] n个小伙伴(编号从 0 到 n−1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从 0 到 n−1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……, ...

  10. NXP ARM Vector Table CheckSum

    Signature Creator for NXP Cortex-M Devices Algorithm for creating the checksum The reserved Cortex-M ...