实现简单动画:
在drawable目录中放入图片,
并且创建xml文件 frame.xml 存入图片,如下:
- <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">
- <!-- 可以重复添加,实现循环 -->
- <!-- 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>
-
-
- </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>此时,在清单中注册后就可以运行并实现了</h3>
posted @
2014-07-30 14:21
新感觉
阅读(
292)
评论()
编辑
收藏
举报