码迷,mamicode.com
首页 > 移动开发 > 详细

android中的动画之变化动画事例2

时间:2016-09-18 13:44:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

之前,我已经说了下,关于变换动画的糅合。在这里,我将说的是,写一个动画集AnimationSet(我们知道,在JAVA中有set容器,而set容器的特点就是:1.无序2.不含重复元素。相当于是数学中的集合)用来存放多个Animation对象,这是JAVA代码的方法,还有一个方法就是在anim下的xml代码写一个集合,用来存放多个动画,我在这里用的是第二种方法

anim文件下的xml代码

xml代码

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <set xmlns:android="http://schemas.android.com/apk/res/android"
 3     >
 4     <alpha
 5         android:duration="2000"
 6         android:fromAlpha="0.0"
 7         android:toAlpha="1.0"
 8         android:fillAfter="true"
 9         />
10     <alpha
11         android:startOffset="2000"
12         android:fromAlpha="1.0"
13         android:toAlpha="0.0"
14         android:duration="2000"
15         android:fillBefore="true"
16         />
17 </set>

布局文件代码

xml代码

 1  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     tools:context="com.example.Tween_Animation.Alpha_MainActivity" >
 7 
 8     <Button
 9         android:id="@+id/button_scale"
10         android:layout_width="fill_parent"
11         android:layout_height="wrap_content"
12         android:text="@string/button_stringScaleAnimation" />
13 
14     <LinearLayout
15         android:gravity="center"
16         android:layout_width="fill_parent"
17         android:layout_height="fill_parent"
18         android:orientation="vertical" >
19 
20         <ImageView
21             android:id="@+id/imageview_scale"
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:src="@drawable/ic_launcher" />
25     </LinearLayout>
26 
27 </LinearLayout>

activity代码

JAVA代码

 1 package com.example.Demo2;
 2 
 3 
 4 
 5 import com.example.androidanimation.R;
 6 
 7 import android.app.Activity;
 8 import android.os.Bundle;
 9 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.view.animation.Animation;
12 import android.view.animation.AnimationUtils;
13 import android.widget.Button;
14 import android.widget.ImageView;
15 
16 public class MainActivity extends Activity implements OnClickListener{
17     private Button button = null;
18     private ImageView imageview = null;
19     protected void onCreate(Bundle savedInstanceState) {
20         super.onCreate(savedInstanceState);
21         setContentView(R.layout.activity_main);
22         button = (Button) findViewById(R.id.button_scale);
23         imageview = (ImageView) findViewById(R.id.imageview_scale);
24         button.setOnClickListener(this);
25     }
26     public void onClick(View v) {
27         Animation animation = AnimationUtils.loadAnimation(this, R.anim.demo2);
28         imageview.startAnimation(animation);
29     }
30 }

经过我们就可以使用一个集合来加载一个动画了,是不是很神奇啊?

android中的动画之变化动画事例2

标签:

原文地址:http://www.cnblogs.com/Stay-Hungry-Stay-Foolish/p/5881192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!