Android 补间动画
来源:互联网 发布:蛙5火箭知乎 编辑:程序博客网 时间:2024/05/16 14:29
直接上代码(来自 android范例大全这本书)
布局文件 4 个
//anim_alpha.xml<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><alpha android:fromAlpha="1" android:toAlpha="0" android:fillAfter="true" android:repeatMode="reverse" android:repeatCount="1" android:duration="2000"/></set>
//anim_rotate.xml<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><rotate android:interpolator="@android:anim/accelerate_interpolator" android:fromDegrees="0" android:toDegrees="720" android:pivotX="50%" android:pivotY="50%" android:duration="2000"></rotate><rotate android:interpolator="@android:anim/accelerate_interpolator" android:startOffset="2000" android:fromDegrees="360" android:toDegrees="0" android:pivotX="50%" android:pivotY="50%" android:duration="2000"></rotate></set>
//anim_scale.xml<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><scale android:fromXScale="1" android:interpolator="@android:anim/decelerate_interpolator" android:fromYScale="1" android:toXScale="2.0" android:toYScale="2.0" android:pivotX="50%" android:pivotY="50%" android:fillAfter="true" android:repeatCount="1" android:repeatMode="reverse" android:duration="2000"/></set>
//anim_translate<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><translate android:fromXDelta="0" android:toXDelta="860" android:fromYDelta="0" android:toYDelta="0" android:fillAfter="true" android:repeatMode="reverse" android:repeatCount="1" android:duration="2000"></translate> </set>
// 入口activity
package com.myapplicatio10.wheee.myapplication10;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends Activity { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Animation rotate = AnimationUtils.loadAnimation(this, R.anim.anim_rotate); //获取“旋转”动画资源 final Animation translate = AnimationUtils.loadAnimation(this, R.anim.anim_translate); //获取“平移”动画资源 final Animation scale = AnimationUtils.loadAnimation(this, R.anim.anim_scale); //获取“缩放”动画资源 final Animation alpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha); //获取“透明度变化”动画资源 final ImageView iv = (ImageView) findViewById(R.id.imageView1); //获取要应用动画效果的ImageView final Button button1 = (Button) findViewById(R.id.button1); //获取“旋转”按钮 button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { button1 .startAnimation(translate); //播放“平移”动画 iv.startAnimation(scale); //播放“缩放”动画 } }); Button button2 = (Button) findViewById(R.id.button2); //获取“平移”按钮 button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { iv.startAnimation(translate); //播放“平移”动画 } }); Button button3 = (Button) findViewById(R.id.button3); //获取“缩放”按钮 button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { iv.startAnimation(scale); //播放“缩放”动画 } }); Button button4 = (Button) findViewById(R.id.button4); //获取“透明度渐变”按钮 button4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { iv.startAnimation(alpha); //播放“透明度渐变”动画 } }); }}// FrameLayout frameLayout = (FrameLayout) findViewById(R.id.f_1);// MyClass myClass = new MyClass(this);// frameLayout.addView(myClass);
即可实现。
在此记录
0 0
- Android-补间动画
- Android-补间动画
- Android 补间动画
- Android补间动画
- Android 补间动画
- Android 补间动画
- Android 补间动画
- Android补间动画
- Android补间动画
- android 补间动画
- Android 补间动画
- Android补间动画
- Android 动画-----补间动画
- Android动画--补间动画
- android动画 -- 帧动画 补间动画
- Android动画-帧动画&补间动画
- 2. android补间动画
- android移动补间动画
- WPF编程宝典读书笔记——第10章 资源(一)
- 取出一个字符串中字母出现的次数。如:字符串:"abcde%^kka27qoq" ,输出格式为: a(2)b(1)k(2)...
- Alice and Bob
- POJ 2406 Power Strings (kmp求循环节)
- Android中的事件分发和处理
- Android 补间动画
- SharedPreferences 监听变化Listener 的onSharedPreferenceChanged方法没有调用
- Iframe实现Ajax文件上传Servlet响应上传结果
- C#:网络通信(TCP)
- 第一章.对象导论之方法的重写和重载
- HDOJ 5744 Keep On Movin(最大化最短回文串长度)
- 使用新浪SAE平台的Storage存储,如何将存入的数据,下载到本地。爬坑之旅。
- mongodb_修改器($inc/$set/$unset/$push/$pop/upsert......)
- std::unique (去重)