日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Android成长之路-实现简单动画

發(fā)布時間:2025/5/22 121 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android成长之路-实现简单动画 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

實現(xiàn)簡單動畫:

在drawable目錄中放入圖片,

并且創(chuàng)建xml文件?frame.xml?存入圖片,如下:

[java] view plaincopy
  • <pre?class="html"?name="code"><?xml?version="1.0"?encoding="utf-8"?>??
  • <animation-list?xmlns:android="http://schemas.android.com/apk/res/android"??
  • ????android:oneshot="false">??
  • ????<!--?可以重復添加,實現(xiàn)循環(huán)?-->??
  • ????<!--?android:duration="100"設置的是圖片持續(xù)的時間長短?-->??
  • ????<item?android:drawable="@drawable/girl_1"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_2"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_3"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_4"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_5"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_6"?android:duration="200"?/>??
  • ????<item?android:drawable="@drawable/girl_7"?android:duration="300"?/>??
  • ????<item?android:drawable="@drawable/girl_6"?android:duration="200"?/>??
  • ????<item?android:drawable="@drawable/girl_7"?android:duration="300"?/>??
  • ????<item?android:drawable="@drawable/girl_8"?android:duration="200"?/>??
  • ????<item?android:drawable="@drawable/girl_9"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_10"?android:duration="100"?/>??
  • ????<item?android:drawable="@drawable/girl_11"?android:duration="100"?/>??
  • ??
  • </animation-list>??
  • ??
  • ??
  • </pre><br>??
  • <pre></pre>??
  • <h3><a?name="t3"></a>然后定義一個布局frame_layout.xml:</h3>??
  • <pre?class="html"?name="code"><?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"??
  • ????android:orientation="vertical"??
  • ????android:gravity="center"?>??
  • ??
  • ????<!--?承載圖片?-->??
  • ????<ImageView??
  • ????????android:id="@+id/frameIV"??
  • ????????android:layout_width="wrap_content"??
  • ????????android:layout_height="wrap_content"??
  • ????????/>??
  • ??
  • </LinearLayout></pre>??
  • <p><br>??
  • ?</p>??
  • <h3><a?name="t4"></a>然后寫activity類,FrameActivity.java:</h3>??
  • <pre?class="java"?name="code">package?cn.class3g.animation;??
  • ??
  • import?android.app.Activity;??
  • import?android.graphics.drawable.AnimationDrawable;??
  • import?android.os.Bundle;??
  • import?android.view.MotionEvent;??
  • import?android.widget.ImageView;??
  • ??
  • public?class?FrameActivity?extends?Activity?{??
  • ??
  • ????AnimationDrawable?attackAnimation;//定義動畫對象??
  • ????ImageView?frameIV;??
  • ??????
  • ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  • ????????super.onCreate(savedInstanceState);??
  • ????????this.setContentView(R.layout.frame_layout);??
  • ??????????
  • ????????init();??
  • ????}??
  • ??
  • ????private?void?init()?{??
  • ????????frameIV?=?(ImageView)?this.findViewById(R.id.frameIV);??
  • ????????frameIV.setBackgroundResource(R.drawable.frame);//得到圖片并添加到布局中(當作背景圖片)??
  • ????????attackAnimation?=?(AnimationDrawable)?frameIV.getBackground();//得到背景圖片給動畫對象??
  • ??????????
  • ????}??
  • ????//點擊屏幕觸發(fā)??
  • ????public?boolean?onTouchEvent(MotionEvent?event)?{??
  • ????????if(event.getAction()?==?MotionEvent.ACTION_DOWN){??
  • ????????????attackAnimation.start();//點擊屏幕后啟動動畫??
  • ????????}??
  • ????????return?super.onTouchEvent(event);??
  • ????}??
  • ??????
  • ??????
  • ??
  • }??
  • </pre>??
  • <p><br>??
  • ?</p>??
  • <h3><a?name="t5"></a>此時,在清單中注冊后就可以運行并實現(xiàn)了</h3>?
  • 《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的Android成长之路-实现简单动画的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。