在ViewFlipper中使用Rotate3dAnimation旋转切换界面效果
来源:互联网 发布:淘宝网阿里旺旺打不开 编辑:程序博客网 时间:2024/06/14 07:20
Rotate3dAnimation是google api demo中copy出来的,具体的例子在Views/Animation/3D Transition中。
这里我就直接贴了:
接下来就是要在ViewFlipper中使用它了,
首先在布局中加入2个view,类似:
然后通常在代码中怎样写:
我这里是按一个按钮将2个ListView翻来覆去的3D旋转显示。
这样一个简单的3D旋转效果就出来了。就是感觉景深效果不太好,比较生硬,没iphone自然。
随手势滑动的3D旋转效果
http://www.eoeandroid.com/thread-203645-1-1.html
android 类似微信的摇一摇实现
这里我就直接贴了:
package com.ata.util;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); }}
接下来就是要在ViewFlipper中使用它了,
首先在布局中加入2个view,类似:
<ViewFlipper android:id="@+id/viewFlipper" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include layout="@layout/layout_0"/> <include layout="@layout/layout_1"/> </ViewFlipper>
然后通常在代码中怎样写:
我这里是按一个按钮将2个ListView翻来覆去的3D旋转显示。
View.OnClickListener onClickListener=new View.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubfloat halfWidth=viewFlipper.getWidth()/2.0f;float halfHeight=viewFlipper.getHeight()/2.0f;int duration=500;int depthz=0;//viewFlipper.getWidth()/2;if(btn_rightTop.getText().equals("日历视图")){btn_rightTop.setText("分类视图");Rotate3dAnimation in=new Rotate3dAnimation(-90, 0,halfWidth,halfHeight,depthz,false); in.setDuration(duration); in.setStartOffset(duration);viewFlipper.setInAnimation(in); Rotate3dAnimation out=new Rotate3dAnimation(0, 90,halfWidth,halfHeight,depthz,false); out.setDuration(duration); viewFlipper.setOutAnimation(out); viewFlipper.showNext(); }else{btn_rightTop.setText("日历视图");Rotate3dAnimation in=new Rotate3dAnimation(90, 0,halfWidth,halfHeight,depthz,false); in.setDuration(duration); in.setStartOffset(duration);viewFlipper.setInAnimation(in); Rotate3dAnimation out=new Rotate3dAnimation(0, -90,halfWidth,halfHeight,depthz,false); out.setDuration(duration); viewFlipper.setOutAnimation(out); viewFlipper.showPrevious(); }}};
这样一个简单的3D旋转效果就出来了。就是感觉景深效果不太好,比较生硬,没iphone自然。
随手势滑动的3D旋转效果
http://www.eoeandroid.com/thread-203645-1-1.html
android 类似微信的摇一摇实现
http://www.cnblogs.com/jxgxy/archive/2012/08/29/2662138.html
0 0
- 在ViewFlipper中使用Rotate3dAnimation旋转切换界面效果
- 在ViewFlipper中使用Rotate3dAnimation旋转切换界面效果
- ViewFlipper实现界面切换效果
- 使用ViewSwitcher和ViewFlipper在不同布局中切换
- 使用ViewSwitcher和ViewFlipper在不同布局中切换
- 使用ViewFlipper实现屏幕切换动画效果
- 使用ViewFlipper实现屏幕切换动画效果
- 使用ViewFlipper实现屏幕切换动画效果
- WebView在ViewFlipper中 实现 切换
- Android中Activity多页滑动切换效果(使用ViewFlipper)
- 使用D3DMobile组件在WM6系统中建立立体界面切换效果
- Android中使用ViewFlipper实现屏幕切换
- Android学习-使用ViewFlipper实现屏幕切换的动画效果
- ViewFlipper效果-------滑动切换页面
- ViewFlipper界面自动切换和滑动切换
- Android开发中ViewFlipper和ViewSwitcher使用GestureDetector完成切换
- Android 中3d旋转动画Rotate3dAnimation大图旋转失真的问题
- ViewFlipper实现界面的滑动切换
- Android实现推送PushService通知Notification
- 图片下载工具类:BitmapUtil
- android 再按一次后退键退出应用程序
- 双指拖动缩放图片
- 使用FileObserver对sdcard文件或文件夹监控
- 在ViewFlipper中使用Rotate3dAnimation旋转切换界面效果
- 初识QT2
- 3518: 点组计数
- Android 数据库打包随APK发布
- 高并发高可用的 架构实践
- 使用Service和BroadcastReceiver实时监听网络状态
- Android-20170410
- ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)
- BZOJ 4521 [Cqoi2016] 手机号码