-
Android成长之路-实现简单动画
实现简单动画:
在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>
-
相关阅读:
Eclipse搭建springboot项目(八)拦截器、过滤器、监听器
JAVA LOG
Eclipse搭建springboot项目(七)启动方式
Eclipse搭建springboot项目(六)全局异常
Eclipse搭建springboot项目(五)单元测试
Eclipse搭建springboot项目(四)热部署
Eclipse搭建springboot项目(三)配置文件自动注入+文件上传需求
报错
Eclipse搭建springboot项目(二)springboot目录
Linux window查询网络端口
-
原文地址:https://www.cnblogs.com/xgjblog/p/3877949.html
Copyright © 2020-2023
润新知