当前位置:首页 » 安卓系统 » android旋转图片动画

android旋转图片动画

发布时间: 2022-06-25 21:05:54

❶ android 怎么在轮播时实现多种动画效果,如第一张到第二张渐变,第二张到第三张旋转

Android系统自带的一个多页面管理控件,它可以实现子界面的自动切换:

首先 需要为ViewFlipper加入View

(1) 静态导入:在layout布局文件中直接导入

(2) 动态导入:addView()方法

ViewPlipper常用方法:

setInAnimation:设置View进入屏幕时候使用的动画

setOutAnimation:设置View退出屏幕时候使用的动画

showNext:调用该函数来显示ViewFlipper里面的下一个View

showPrevious:调用该函数来显示ViewFlipper里面的上一个View

setFlipInterval:设置View之间切换的时间间隔

startFlipping使用上面设置的时间间隔来开始切换所有的View,切换会循环进行

stopFlipping:停止View切换

讲了这么多,那么我们今天要实现的是什么呢?

(1) 利用ViewFlipper实现图片的轮播

(2) 支持手势滑动的ViewFlipper

我们需要先准备几张图片:把图片放进drawable中

创建两个动画:在res下面新建一个folder里面新建两个xml:

❷ 在android中,某图片使用rotateanimation动画,如何绕着这个图片的左下角的进行旋转

1、定义一个ImageView
定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。
资源文件为

复制代码代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/infoOperating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/operating"
android:scaleType="center">
</ImageView>
</LinearLayout>

其中的android:src为图片内容,可使用附件中的图片。
java代码为

复制代码代码如下:

ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating);

2、定义rotate旋转效果
在res/anim文件夹下新建tip.xml文件,内容如下

复制代码代码如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="359"
android:ration="500"
android:repeatCount="-1"
android:pivotX="50%"
android:pivotY="50%" />
</set>

含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。

java代码为

复制代码代码如下:

Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);

setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。
a. 关于其中的属性意义如下(红色部分加以注意):
android:fromDegrees 起始的角度度数
android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大3600即可
android:pivotX 旋转中心的X坐标
浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心
android:pivotY 旋转中心的Y坐标
浮点数或是百分比。浮点数表示相对于Object的上边缘,如5; 百分比表示相对于Object的上边缘,如5%; 另一种百分比表示相对于父容器的上边缘,如5%p; 一般设置为50%表示在Object中心
android:ration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。
android:interpolator表示变化率,但不是运行速度。一个插补属性,可以将动画效果设置为加速,减速,反复,反弹等。默认为开始和结束慢中间快,
android:startOffset 在调用start函数之后等待开始运行的时间,单位为毫秒,若为10,表示10ms后开始运行
android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止
android:repeatMode 重复的模式,默认为restart,即重头开始重新运行,可以为reverse即从结束开始向前重新运行。在android:repeatCount大于0或为infinite时生效
android:detachWallpaper 表示是否在壁纸上运行
android:zAdjustment 表示被animated的内容在运行时在z轴上的位置,默认为normal。
normal保持内容当前的z轴顺序
top运行时在最顶层显示
bottom运行时在最底层显示
b. 运行速度
运行速度为运行时间(android:ration)除以运行角度差(android:toDegrees-android:fromDegrees),比如android:ration为1000,android:toDegrees为360,android:fromDegrees为0就表示1秒转1圈。
c. 循环运行

复制代码代码如下:

android:fromDegrees="0"
android:toDegrees="360"
android:repeatCount="-1"

android:repeatCount="-1"即表示循环运行,配合上android:fromDegrees="0" android:toDegrees="360"表示不间断
3、开始和停止旋转
在操作开始之前调用

复制代码代码如下:

if (operatingAnim != null) {
infoOperatingIV.startAnimation(operatingAnim);
}

在操作完成时调用

复制代码代码如下:

infoOperatingIV.clearAnimation();

许多朋友不知道如何停止旋转animation,所以强制设置rotate转动多少圈表示操作,但却无法与操作实际的进度匹配上,实际上只要如上代码所示清除animation即可。
其他:
对于上面的转动在横屏(被设置为了不重绘activity)时会出现问题,即旋转中心偏移,导致动画旋转偏离原旋转中心。解决如下

复制代码代码如下:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) {
infoOperatingIV.clearAnimation();
infoOperatingIV.startAnimation(operatingAnim);
}
}

❸ android怎么实现一张图片旋转几秒后后自动换到另一张图片

图片旋转使用动画,设置动画时间,旋转完成后,设置另一张图片

RotateAnimation 动画,
RotateAnimation (float fromDegrees, float toDegrees, int
pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:

float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int
pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotXValue:X坐标的伸缩值。
int
pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float
pivotYValue:Y坐标的伸缩值。

❹ android怎么实现图片旋转

可以使用RotateAnimation动画实现,设定无限循环即可

代码如下

{

ImageViewiv;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
iv=(ImageView)findViewById(R.id.image);
RotateAnimationanimation=newRotateAnimation(0,360);
animation.setDuration(100000);//设定转一圈的时间
animation.setRepeatCount(Animation.INFINITE);//设定无限循环
animation.setRepeatMode(Animation.RESTART);
iv.startAnimation(animation);
}
}


也可以自定义view继承于imageview,启动一个线程,在while循环里设置view的旋转角度


{

privatefloatmCurDegree=0;//当前旋转角度
publicRotateView(Contextcontext,AttributeSetattrs){
super(context,attrs);
newThread(this).start();
}

@Override
protectedvoidonLayout(booleanchanged,intleft,inttop,intright,
intbottom){
super.onLayout(changed,left,top,right,bottom);
//设定旋转中心
setPivotX(getMeasuredWidth()/2);
setPivotY(getMeasuredHeight()/2);
}

@Override
publicvoidrun(){
while(true){
setRotation(mCurDegree);
mCurDegree+=5;
postInvalidate();
SystemClock.sleep(16);
}
}
}

在布局文件里使用RotateView代替imageview即可

❺ Android 旋转动画

<rotate
android:fromDegrees="45"//起始旋转的角度
android:toDegrees="89"//结束选装后的角度
android:ration="500"//执行时间为500ms
android:pivotX="50%"//距离控件左边缘50%
android:pivotY="50%"//距离控件上边缘50%(与上边结合就是控件中心)
android:fillEnabled="true"
android:fillAfter="true"//动画执行完后停留在执行完的状态
/>

—————————————————————————————————————————

当然也可以通过代码用animation实现

好久没写,应该是

RotateAnimationanimation=newRotateAnimation(0f,45f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(500);
view.setAnimation(animation);

❻ android 的动画效果怎么做

1. Tween Animation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果,即是一种渐变动画;
2. Frame Animation:顺序播放事先做好的图像,是一种画面转换动画。
动画类型
下面先来看看Android提供的动画类型。Android的animation由四种类型组成
在XML文件中:
alpha 渐变透明度动画效果
scale 渐变尺寸伸缩动画效果
translate 画面转换位置移动动画效果
rotate 画面转移旋转动画效果
在Java 源码中定义了相应的类,可以使用这些类的方法来获取和操作相应的属性:
AlphaAnimation渐变透明度动画效果
ScaleAnimation渐变尺寸伸缩动画效果
TranslateAnimation画面转换位置移动动画效果
RotateAnimation画面转移旋转动画效果

❼ android怎么实现一张图片以它的对角线进行翻转的动画

3.0以上,有个ObjectAnimator可以实现

给你个动画集源代码,里面有各种android的动画效果

其中有一个界面就有这个动画

❽ 如何实现Rotate旋转动画的android源代码

android源代码之Rotate旋转动画
标签为旋转节点
Tween一共为我们提供了3种动画渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 设置动画渲染器为加速动画(动画播放中越来越快)
android:interpolator="@android:anim/decelerate_interpolator" 设置动画渲染器为减速动画(动画播放中越来越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 设置动画渲染器为先加速在减速(开始速度最快 逐渐减慢)
如果不写的话 默认为匀速运动
android:fromDegrees="+360"设置动画开始的角度
android:toDegrees="0"设置动画结束的角度
这个动画布局设置动画将向左做360度旋转加速运动。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
复制代码
代码实现
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋转动画按钮**/
Button mButton0 = null;
/**向右旋转动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**向左旋转动画**/
Animation mLeftAnimation = null;
/**向右旋转动画**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载向左与向右旋转动画**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋转动画**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋转动画**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}
学习更多关于android源代码,可以查询

❾ 安卓开发旋转动画实现的时候为什么会刷新界面

Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果;第二类是 Frame 动画,即顺序播放事先做好的图像,跟电影类似。本文分析 Tween动画的rotate实现旋转效果。 在新浪微博客户端中各个操作进行中时activity的右上角都会有个不停旋转的图标,类似刷新的效果,给用户以操作中的提示。这种非模态的提示方式推荐使用,那么下面就分享下如何实现这种效果吧 1、定义一个ImageView 定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。 资源文件为 Java代码 xmlns:android="schemas/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> android:id="@+id/infoOperating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/operating" android:scaleType="center"> 其中的android:src为图片内容,可使用附件中的图片。 java代码为 Java代码 ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating); 2、定义rotate旋转效果 在res/anim文件夹下新建tip.xml文件,内容如下 Java代码 android:fromDegrees="0" android:toDegrees="359" android:ration="500" android:repeatCount="-1" android:pivotX="50%" android:pivotY="50%" /> 含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。 java代码为 Java代码 Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。 a. 关于其中的属性意义如下(红色部分加以注意): android:fromDegrees 起始的角度度数 android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大3600即可 android:pivotX 旋转中心的X坐标 浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心 android:pivotY 旋转中心的Y坐标 浮点数或是百分比。浮点数表示相对于Object的上边缘,如5; 百分比表示相对于Object的上边缘,如5%; 另一种百分比表示相对于父容器的上边缘,如5%p; 一般设置为50%表示在Object中心 android:ration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。 android:interpolator表示变化率,但不是运行速度。一个插补属性,可以将动画效果设置为加速,减速,反复,反弹等。默认为开始和结束慢中间快, android:startOffset 在调用start函数之后等待开始运行的时间,单位为毫秒,若为10,表示10ms后开始运行 android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止 android:repeatMode 重复的模式,默认为restart,即重头开始重新运行,可以为reverse即从结束开始向前重新运行。在android:repeatCount大于0或为infinite时生效 android:detachWallpaper 表示是否在壁纸上运行 android:zAdjustment 表示被animated的内容在运行时在z轴上的位置,默认为normal。 normal保持内容当前的z轴顺序 top运行时在最顶层显示 bottom运行时在最底层显示 b. 运行速度 运行速度为运行时间(android:ration)除以运行角度差(android:toDegrees-android:fromDegrees),比如android:ration为1000,android:toDegrees为360,android:fromDegrees为0就表示1秒转1圈。 c. 循环运行 Java代码 android:fromDegrees="0" android:toDegrees="360" android:repeatCount="-1" android:repeatCount="-1"即表示循环运行,配合上android:fromDegrees="0" android:toDegrees="360"表示不间断 3、开始和停止旋转 在操作开始之前调用 Java代码 if (operatingAnim != null) { infoOperatingIV.startAnimation(operatingAnim); } 在操作完成时调用 Java代码 infoOperatingIV.clearAnimation(); 许多朋友不知道如何停止旋转animation,所以强制设置rotate转动多少圈表示操作,但却无法与操作实际的进度匹配上,实际上只要如上代码所示清除animation即可。 其他: 对于上面的转动在横屏(被设置为了不重绘activity)时会出现问题,即旋转中心偏移,导致动画旋转偏离原旋转中心。解决如下 Java代码 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) { infoOperatingIV.clearAnimation(); infoOperatingIV.startAnimation(operatingAnim); } }

❿ android中怎么定义旋转动画的旋转速度

android源代码之Rotate旋转动画
标签为旋转节点
Tween一共为我们提供了3种动画渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 设置动画渲染器为加速动画(动画播放中越来越快)
android:interpolator="@android:anim/decelerate_interpolator" 设置动画渲染器为减速动画(动画播放中越来越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 设置动画渲染器为先加速在减速(开始速度最快 逐渐减慢)
如果不写的话 默认为匀速运动
android:fromDegrees="+360"设置动画开始的角度
android:toDegrees="0"设置动画结束的角度
这个动画布局设置动画将向左做360度旋转加速运动。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
复制代码
代码实现
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋转动画按钮**/
Button mButton0 = null;
/**向右旋转动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**向左旋转动画**/
Animation mLeftAnimation = null;
/**向右旋转动画**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载向左与向右旋转动画**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋转动画**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋转动画**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}

热点内容
綦江dns服务器地址 发布:2024-05-05 15:04:11 浏览:555
山东省日照市监控服务器地址 发布:2024-05-05 15:03:59 浏览:341
java提升教程 发布:2024-05-05 15:00:51 浏览:144
驱动编译龙芯 发布:2024-05-05 14:41:31 浏览:957
起什么密码 发布:2024-05-05 14:29:48 浏览:562
安卓怎么设置锁屏时不显示微信通话 发布:2024-05-05 14:21:59 浏览:223
qq怎么访问照片流 发布:2024-05-05 14:20:38 浏览:17
java实现的加密算法 发布:2024-05-05 14:20:33 浏览:183
基础it编程的书籍 发布:2024-05-05 14:19:47 浏览:442
网易梦之国服务器ip 发布:2024-05-05 14:06:11 浏览:34