Android成長之路-實現簡單動畫

來源:互聯網
上載者:User
文章目錄
  • 實現簡單動畫:
  • 在drawable目錄中放入圖片,
  • 並且建立xml檔案 frame.xml 存入圖片,如下:
  • 然後定義一個布局frame_layout.xml:
  • 然後寫activity類,FrameActivity.java:
  • 此時,在清單中註冊後就可以運行並實現了
實現簡單動畫:在drawable目錄中放入圖片,

並且建立xml檔案 frame.xml 存入圖片,如下:
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="false"><!-- 可以重複添加,實現迴圈 --><!-- android:duration="100"設定的是圖片持續的時間長短 --><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>

然後定義一個布局frame_layout.xml:
<?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>

 

然後寫activity類,FrameActivity.java:
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();//得到背景圖片給動畫對象}//點擊螢幕觸發public boolean onTouchEvent(MotionEvent event) {if(event.getAction() == MotionEvent.ACTION_DOWN){attackAnimation.start();//點擊螢幕後啟動動畫}return super.onTouchEvent(event);}}

 

此時,在清單中註冊後就可以運行並實現了
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.