用开源项目FlipImageView实现图片的翻转效果

开源项目地址: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实现图片的翻转效果的更多相关文章
- css3图片3D翻转效果
点击图片看翻转效果 html结构 <div class="flip"> <div class="front"> <img src= ...
- 基于jQuery遮罩图片hover翻转效果
基于jQuery遮罩图片hover翻转效果.这是一款基于jQuery+css3实现的鼠标经过遮罩图片翻转特效.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div cla ...
- 用开源项目CropImage实现图片的裁剪(不推荐)
之前介绍过一个截图的办法(http://www.cnblogs.com/tianzhijiexian/p/3900241.html),这里再分享个开源项目.它也是截图,但是效果不是很好,首先还是 ...
- 用开源项目PhotoView实现图片的双指缩放和双击放大缩小
项目地址:https://github.com/chrisbanes/PhotoView 用开源项目有个好处,一是实现简单,二是bug少.那么我们就来说下这个项目能够实现的效果: 1.单个图片的双指缩 ...
- CSS3之图片3D翻转效果(网页效果--每日一更)
今天,带来的是纯CSS3的效果--图片3D翻转. 请看效果:亲,请点击这里 这个效果主要还是运用了CSS3的transform变形属性,与上个效果不同的是,这次并不是动画,所以没有采用animatio ...
- 图片触及翻转效果 css3
实现图片由左向右飞入回到最初设定位置 ,鼠标浮上去旋转显示另一张图片效果: html: <!DOCTYPE HTML> <html> <head> <meta ...
- Android 开源项目分类汇总(转)
Android 开源项目分类汇总(转) ## 第一部分 个性化控件(View)主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Galler ...
- HTML和CSS实现图片翻转效果
实现图片翻转,首先来分析一下我们希望实现的是怎样的翻转效果?又该如何去实现呢? 一.希望实现的效果 页面上的图片在光标悬停在上面的时候会发生翻转效果,翻转过后显示出背面的说明文字. 鼠标没有悬停在上面 ...
- Android 图片加载[常见开源项目汇总]
该文主要是讲一下目前有哪些使用比较多的 图片加载开源项目,并简单介绍该如果使用 以及各开源项目之间有什么区别, 我们该如何去选择适合的开源项目应用到我们的项目中? 一.Android-Universa ...
随机推荐
- asserts文件存到外部SD卡里
package com.example.wang.testapp3; import android.content.res.AssetManager; import android.graphics. ...
- Amazon电商数据分析——数据获取
最近一段时间主要重心在Amazon电商数据分析上,这是一个偏数据分析和可视化的项目.具体来说就是先获取Amazon的商品数据,数据清洗和持久化存储后作为我们自己的数据源.分析模块和可视化模块基于数据进 ...
- 关于spark ui中executor显示的内存量与设置的内存量不符的问题
executor显示的内存量是实际执行程序使用的内存量,也就是排除bspark.storage.memoryFraction设置的比例外,然后使用的内存量. 默认是0.6,所以executory和dr ...
- (转载)ACM训练计划,先过一遍基础再按此拼搏吧!!!!
ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. USACO ht ...
- 016.Zabbix聚合监控
一 Zabbix监控机汇总计算 用Calcuated Items可以对Items进行汇总计算,如求磁盘总容量.网络流量,只依赖于Zabbix-Server,与Zabbix-Agent和proxy无关. ...
- Oracle - 数据库巡检脚本
分享一个oracle数据库巡检脚本,欢迎大家使用,希望大家在用的过程中发现脚本中的错误并提出改进意见. -- 数据库巡检脚本 -- 版本号2.1 -- 该脚本仅对数据库的做一个初步的巡检,具体的优化方 ...
- 关于我学XSS躺过的那些坑
XSS字符编码 在学习编码绕过时由于数量多,类型相似,不太容易记得住,记得全,故做此记录. 0x01 Html标签属性中执行 简单了解: Html标签属性中的XSS问题多属于javascript伪协议 ...
- java中关于锁知识的整理
1.1什么是锁? 在计算机科学中,锁(lock)或互斥(mutex)是一种同步机制,用于在有许多执行线程的环境中强制对资源的访问限制.锁旨在强制实施互斥排他.并发控制策略. 锁通常需要硬件支持才能有效 ...
- JAVA JMX协议监控
JMX协议监控,可通过JMX协议远程监控,实时监控线上jvm情况,并通过平台管理界面进行 展示,可以通过监控实时获得线上服务器运行情况. 可以监控内存.实时线程.共享内存等各种信息. 获取实时线程信息 ...
- ios手机填坑总结
1. 日期格式 ios系统.safari只能识别"2018/10/15 00:00:00",不能识别"2018-10-15 00:00:00",所以需要转换格式 ...