zoukankan      html  css  js  c++  java
  • 逐帧动画(Frame-by-frame Animations)

    1.这一类动画可以创建一个Drawable序列,这些Drawable可以按照指定的时间间歇一个一个的显示.

     xml定义方法

    1 <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    2     android:oneshot="false">
    3  <item android:drawable="tu1" android:duration="200"/>
    4  <item android:drawable="tu2" android:duration="200"/>
    5  <item android:drawable="tu3" android:duration="200"/>
    6 </animation-list>

    2.逐帧动画是在drawable下创建的一种图片,根节点是animation-list(动画列表),oneshot属性表示是否只播放一次,内部用item节点声明一个个的动画。

     其中drawable指明使用的图片,duration属性这一动画显示的时间,单位毫秒。

       然后可以将其当做背景图片来使用

    1 <TextView
    2     android:id="@+id/main_tv"
    3     android:layout_width="100dp"
    4     android:layout_height="100dp"
    5     android:background="@drawable/animation_list"/>

    3.然开在代码中开始播放动画即可

    1 ((AnimationDrawable)img.getBackground()).start();

    //=============

      实例:帧动画

    效果图:

              

    Demo1appsrcmain esdrawableanim_frame.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:oneshot="false">
     4     <item
     5         android:drawable="@drawable/aa"
     6         android:duration="500" />
     7     <item
     8         android:drawable="@drawable/bb"
     9         android:duration="500" />
    10     <item
    11         android:drawable="@drawable/cc"
    12         android:duration="500" />
    13     <item
    14         android:drawable="@drawable/dd"
    15         android:duration="500" />
    16     <item
    17         android:drawable="@drawable/ee"
    18         android:duration="500" />
    19     <item
    20         android:drawable="@drawable/ff"
    21         android:duration="500" />
    22 </animation-list>

    Demo1appsrcmain eslayoutactivity_main.xml

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     tools:context=".MainActivity">
     6 
     7     <ImageView
     8         android:id="@+id/main_img"
     9         android:layout_width="100dp"
    10         android:layout_height="180dp"
    11         android:layout_centerHorizontal="true"
    12         android:layout_centerVertical="true"
    13         android:background="@drawable/anim_frame"/>
    14 </RelativeLayout>

    Demo1appsrcmainjavacomlydemo1MainActivity.java

     1 package com.ly.demo1;
     2 
     3 import android.app.Activity;
     4 import android.graphics.drawable.AnimationDrawable;
     5 import android.os.Bundle;
     6 import android.widget.ImageView;
     7 
     8 public class MainActivity extends Activity {
     9     private ImageView img;
    10 
    11     @Override
    12     protected void onCreate(Bundle savedInstanceState) {
    13         super.onCreate(savedInstanceState);
    14         setContentView(R.layout.activity_main);
    15         img = (ImageView) findViewById(R.id.main_img);
    16         ((AnimationDrawable)img.getBackground()).start();
    17     }
    18     
    19 }
  • 相关阅读:
    Linux(Contos7.5)环境搭建之JDK1.8安装(二)
    python微信域名或者链接批量检测
    表单设计器3-查询面板
    表单设计器2-表格布局
    表单设计器1-基本操作
    信息无障碍国内标准
    信息无障碍国际标准
    信息无障碍服务对象
    信息无障碍定义
    E8.Net工作流开发问题
  • 原文地址:https://www.cnblogs.com/LY1124/p/4692614.html
Copyright © 2011-2022 走看看