android中的動畫之變化動畫案例2

來源:互聯網
上載者:User

標籤:

之前,我已經說了下,關於變換動畫的糅合。在這裡,我將說的是,寫一個動畫集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     <alpha11         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     <LinearLayout15         android:gravity="center"16         android:layout_width="fill_parent"17         android:layout_height="fill_parent"18         android:orientation="vertical" >19 20         <ImageView21             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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.