生活随笔
收集整理的這篇文章主要介紹了
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();??????????????}??????????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成长之路-实现简单动画的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。