android 图片 3d 动画,DEMO:transition3d、运用动画实现图片3d翻转效果
模仿系统apiDemos里的范例,去掉了listview,修改为点击图片后,更新图片并播放3d翻转动画。
代码:package com.example.aexh_11_transition3d;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener
{
/**
* 仿照系统的范例,修改成点击图片播放动画更新图片。
* apiDemos范例: com.example.android.apis.animation
* Transition3d
*/
private static final int[] PHOTOS_RESOURCES = new int[]
{ R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6 };
private ImageView mImageview;
private ViewGroup mLayout;
private int mPosition;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageview = (ImageView) findViewById(R.id.p_w_picpathView1);
mImageview.setOnClickListener(this);
mLayout = (ViewGroup) findViewById(R.id.p_w_picpath_layout);// ViewGroup是所有layout的父类
/**
* 下面这句应该是用来压缩大图的,没加上这句运行正常
*/
// Since we are caching large views, we want to keep their cache
// between each animation
mLayout.setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE);
}
@Override
public void onClick(View v)
{
if (v.getId() == R.id.p_w_picpathView1)
{
// Pre-load the p_w_picpath then start the animation
mPosition++;
applyRotation(0, 90);
mImageview.setImageResource(PHOTOS_RESOURCES[mPosition % 6]);
}
}
/**
* Setup a new 3D rotation on the container view.
*
* @param position
* the item that was clicked to show a picture, or -1 to show the
* list
* @param start
* the start angle at which the rotation must begin
* @param end
* the end angle of the rotation
*/
private void applyRotation(float start, float end)
{
// Find the center of the container
final float centerX = mLayout.getWidth() / 2.0f;
final float centerY = mLayout.getHeight() / 2.0f;
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
// 监听动画
rotation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
}
@Override
public void onAnimationRepeat(Animation animation)
{
}
@Override
public void onAnimationEnd(Animation animation)
{
mLayout.post(mAaction);// 刷新layout这个View
}
});
// 启动动画
mLayout.startAnimation(rotation);
}
Runnable mAaction = new Runnable()
{
@Override
public void run()
{
final float centerX = mLayout.getWidth() / 2.0f;
final float centerY = mLayout.getHeight() / 2.0f;
Rotate3dAnimation rotation;
// mImageView.requestFocus();
rotation = new Rotate3dAnimation(90, 180, centerX, centerY, 310.0f, false);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
mLayout.startAnimation(rotation);
}
};
}
系统实现的动画方法:package com.example.aexh_11_transition3d;
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.graphics.Camera;
import android.graphics.Matrix;
/**
* An animation that rotates the view on the Y axis between two specified
* angles. This animation also adds a translation on the Z axis (depth) to
* improve the effect.
*/
public class Rotate3dAnimation extends Animation
{
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
private final boolean mReverse;
private Camera mCamera;
/**
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
* start angle and its end angle. Both angles are in degrees. The rotation
* is performed around a center point on the 2D space, definied by a pair of
* X and Y coordinates, called centerX and centerY. When the animation
* starts, a translation on the Z axis (depth) is performed. The length of
* the translation can be specified, as well as whether the translation
* should be reversed in time.
*
* @param fromDegrees
* the start angle of the 3D rotation
* @param toDegrees
* the end angle of the 3D rotation
* @param centerX
* the X center of the 3D rotation
* @param centerY
* the Y center of the 3D rotation
* @param reverse
* true if the translation should be reversed, false otherwise
*/
public Rotate3dAnimation(float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ, boolean reverse)
{
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight)
{
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
if (mReverse)
{
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
}
else
{
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
android 图片 3d 动画,DEMO:transition3d、运用动画实现图片3d翻转效果相关推荐
- android左右旋转动画效果图,Android新姿势:3D翻转效果原理
首先,android里是没有3D翻转的动画效果的,但是呢,android有提供一个Camera的类,可以利用这个类来实现. 先看代码,Rotate3d是继承了Animation的一个动画类,多余的代码 ...
- Android笔记 动画之tween(补间)动画demo
简介:补间动画:做flash动画时,在两个关键帧中间需要做"补间动画",才能实现图画的运动:插入补间动画后两个关键帧之间的插补帧是由计算机自动运算而得到的.(来自百度百科) dem ...
- c android显示gif动画,MFC显示GIF动画图片
本帖则将讨论如何在MFC的对话框里显示GIF动画图片.一些关于传统控件的美化方法正在研究当中会陆续发帖的. 这是本帖用到的一个VS2008例程. 附件 GifPicture.rar (138.1 K ...
- WPF仿3D照片墙旋转动画Demo
Demo中实现两种方式旋转3照片墙动画,分别是:计时器旋转和WPF动画旋转. ps:WPF动画旋转角度计算还需优化,Demo只是提供思路,借鉴和学习. 1.计时器旋转 XAML: <UserCo ...
- android下雪动画demo,Android的漂浮动画,下雪动画效果剖析.doc
Android的漂浮动画,下雪动画效果剖析 Android 的漂浮动画,下雪动画效果 先看下效果: 1.先得了解下canvas.drawBitmap(mBitmap, mSrcRect, mDestR ...
- 用3D动画来完成的一个立体图片
3D动画效果 开发工具与关键技术:3D动画 作者:沈金凤 年级:18级(5)班 撰写日期:2019年1月28日 3D动画立体图形给人带来非常好的效果,下面是个简单的立体的3D样式,源代码如下: 虽然源 ...
- 图片连续切换动画Demo
//连续动画:一个接一个地显示一系列的图像 NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"d.jp ...
- Android 属性动画ObjectAnimator使用demo,组合动画
//第一个参数:指定执行动画的控件,第二个参数:指定控件的属性,第三个参数是可变长参数 public static ObjectAnimator ofFloat(Object target, Stri ...
- Android动画学习之帧动画
帧动画简介 介绍帧动画之前先了解一下'帧'的概念:帧,影像动画中最小单位,也就是最小的单幅画面.相当于电影脚上的每一格镜头.一帧就是最小的一张单幅画面,多个帧连接在一起就会形成动画.通常所说的帧数,是 ...
- Android\OPhone动画分析之翻转效果
看到很多人在问如何实现三维的翻转效果,所以今天在这里简单的给大家分析一下,其实在APIDemo中就有这样一个例子,那么我们就以其为例来学习Android中的翻转动画效果的实现,首先看一下运行效果如下图 ...
最新文章
- linux启动docker_10分钟快速掌握Docker必备基础知识
- Linux网络编程 | 零拷贝 :sendfile、mmap、splice、tee
- arm9重启ssh服务_部署ssh使用rsa登录配置
- ramda.js api 速查
- 开源流媒体云视频平台EasyDarwin中EasyCMS服务是如何进行命令转发和消息路由的
- XenApp_XenDesktop_7.6实战篇之十三:安装Virtual Delivery Agent For Windows Desktop OS
- JAVA利用JXL导出/生成 EXCEL1
- [短评] 技术研发向市场运营让步
- 成都这家AI语音芯片公司又融了数千万,能“偷袭”科大讯飞不?
- appium 环境配置
- Android底层控制系统设置的命令集合
- angular4监听输入框_angular4兄弟组件交互,监听响应
- error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
- Atitit 知识结构化的艺术 目录 1. 知识信息结构化脑图	2 1.1. 散乱化模式	2 2. 直线排列	2 2.1.1. 直排	2 2.1.2. 链表模式	2 3. 树形排列	2 3.1.
- python将excel数据批量导入sqlserver数据库
- 如何在海外做游戏代理?
- 2022-2028年中国福利彩票行业市场运营格局及发展趋向分析报告
- Modem2G/3G/4G/5G:高通Policy Manager(概述,优势,架构与API,配置与debug方法)
- 判断其他应用正在使用录音机——AudioManager
- 一文最全科普FPGA技术知识
热门文章
- php 虚线怎么画,ps画虚线最详细教程
- exchange创建邮箱组_在 Exchange 2016 中创建用户邮箱
- 解析局域网即时通讯软件安全吗
- 程序员520❤七夕情人节表白代码Html+Js+Css花瓣相册网页模板❤程序员表白必备...
- 微信公众号如何绑定运营者的微信号
- 二十三种设计模式之工厂模式(含Java工厂模式的实现)
- 颜色空间:RGB,CMY,HSV,HSL,Lab,YUV详解
- AI公开课:03月26日未来十年 AI如何进化—圆桌探讨(乌镇智库理事长、CSDN 创始人董事长、智源人工智能研究院副院长)之《AI:昨天 · 今天 · 明天》
- 添加打印机无法搜索计算机,添加打印机搜索不到打印机怎么办
- ArcGIS10.2 安装教程