android帧动画代码示例
来源:互联网 发布:北大青鸟学java编程 编辑:程序博客网 时间:2024/06/10 20:01
package com.luozhikai.demo.viewanimation;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
}
public void alpha(View view){
AlphaAnimation aa = new AlphaAnimation(0.0f,1.0f);
aa.setDuration(2000);//动画播放的时间长度
//aa.setRepeatCount(1);//设置重复的次数,为1时共播放两次
aa.setRepeatCount(Animation.INFINITE);//无限次
aa.setRepeatMode(Animation.REVERSE);//设置重复播放的模式:restart重新播放,reverse倒着播放
//开启动画
iv.startAnimation(aa);
}
public void trans(View view){
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF,0,
Animation.RELATIVE_TO_SELF,1f,
Animation.RELATIVE_TO_SELF,0,
Animation.RELATIVE_TO_SELF,1f);
ta.setDuration(2000);
ta.setRepeatCount(Animation.INFINITE);
ta.setRepeatMode(Animation.REVERSE);
iv.startAnimation(ta);
}
public void scale(View view){
ScaleAnimation sa = new ScaleAnimation(0.2f,2.0f,0.2f,2.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
sa.setDuration(2000);
sa.setRepeatCount(Animation.INFINITE);
sa.setRepeatMode(Animation.REVERSE);
iv.startAnimation(sa);
}
public void rotate(View view){
RotateAnimation ra = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
ra.setDuration(2000);
ra.setRepeatCount(Animation.INFINITE);
ra.setRepeatMode(Animation.REVERSE);
iv.startAnimation(ra);
}
public void all(View view){
AlphaAnimation aa = new AlphaAnimation(0.0f,1.0f);
aa.setDuration(2000);//动画播放的时间长度
//aa.setRepeatCount(1);//设置重复的次数,为1时共播放两次
aa.setRepeatCount(Animation.INFINITE);//无限次
aa.setRepeatMode(Animation.REVERSE);//设置重复播放的模式:restart重新播放,reverse倒着播放
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF,0,
Animation.RELATIVE_TO_SELF,1f,
Animation.RELATIVE_TO_SELF,0,
Animation.RELATIVE_TO_SELF,1f);
ta.setDuration(2000);
ta.setRepeatCount(Animation.INFINITE);
ta.setRepeatMode(Animation.REVERSE);
ScaleAnimation sa = new ScaleAnimation(0.2f,2.0f,0.2f,2.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
sa.setDuration(2000);
sa.setRepeatCount(Animation.INFINITE);
sa.setRepeatMode(Animation.REVERSE);
RotateAnimation ra = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
ra.setDuration(2000);
ra.setRepeatCount(Animation.INFINITE);
ra.setRepeatMode(Animation.REVERSE);
//创建动画集合
AnimationSet set = new AnimationSet(false);//是否统一格式来播放动画,true是,false按各自的动画效果播放
set.addAnimation(aa);
set.addAnimation(ta);
set.addAnimation(sa);
set.addAnimation(ra);
iv.startAnimation(set);
}
}
layout文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:onClick="alpha"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="alpha" />
<Button
android:onClick="trans"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="trans" />
<Button
android:onClick="scale"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="scale" />
<Button
android:onClick="rotate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="rotate" />
<Button
android:onClick="all"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="all" />
</LinearLayout>
<ImageView
android:id="@+id/iv"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:src="@drawable/pic" />
</RelativeLayout>
阅读全文
0 0
- android帧动画代码示例
- android动画-动画分类及代码示例
- android 动画Animation硬代码实现示例
- Android --- Tween动画示例(代码中定义的动画)
- 动画旋转示例代码
- Android --- Frame动画示例
- Android动画示例
- Android动画框架示例
- android属性动画示例
- android Tween动画概括+示例
- Android - LayoutAnimation 动画效果 - 示例
- ViewAnimation帧动画示例
- android ListView示例代码
- android 代码混淆示例
- android 代码混淆示例
- android 代码混淆示例
- Android编译示例代码
- android 代码混淆示例
- C语言获取文件大小
- GSOAP工具的简单使用
- 判断一个字符串是否包含一个子串
- 指针和数组的对比
- 还原vim默认配置或者卸载vim
- android帧动画代码示例
- Sukodu Solver(深搜)
- iOS 视觉差
- redis五种基本数据类型
- CMPP3.0实现物联网卡发短信遇到的问题
- 读取csv文件到数据库
- mybatis基础
- Codeforces831A Unimodal Array
- JavaScript中Array对象