初学Android,图形图像之使用逐帧动画(三十四)

news/2024/7/8 4:51:13 标签: android, 图形, layout, button, encoding, class
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

逐帧动画其实跟动画片的原理是一样的,一段时间内连续播放一组图片,使之看起来像在动一样

下面是一个例子,不用专门说明就可以理解了

定义文件的资源名为girl,放在res->anmi目录下,下面有一个重要的参数 "

class="language-html">class="tags" href="/tags/ANDROID.html" title=android>android:oneshot="false"
如果为true,动画将不会循环播放

class="language-html"><?xml version="1.0" class="tags" href="/tags/ENCODING.html" title=encoding>encoding="utf-8"?>
<animation-list xmlns:class="tags" href="/tags/ANDROID.html" title=android>android="http://schemas.class="tags" href="/tags/ANDROID.html" title=android>android.com/apk/res/class="tags" href="/tags/ANDROID.html" title=android>android"
    class="tags" href="/tags/ANDROID.html" title=android>android:oneshot="false">
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/one" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/two" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/three" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/four" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/five" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
    <item class="tags" href="/tags/ANDROID.html" title=android>android:drawable="@drawable/six" class="tags" href="/tags/ANDROID.html" title=android>android:duration = "60" />
</animation-list>

主界面main中,imageveiw组件对动画资源进行引用

class="language-html"><?xml version="1.0" class="tags" href="/tags/ENCODING.html" title=encoding>encoding="utf-8" ?> 
<LinearLayout xmlns:class="tags" href="/tags/ANDROID.html" title=android>android="http://schemas.class="tags" href="/tags/ANDROID.html" title=android>android.com/apk/res/class="tags" href="/tags/ANDROID.html" title=android>android" class="tags" href="/tags/ANDROID.html" title=android>android:orientation="vertical" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="fill_parent" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="fill_parent" class="tags" href="/tags/ANDROID.html" title=android>android:background="#fff">
- <LinearLayout xmlns:class="tags" href="/tags/ANDROID.html" title=android>android="http://schemas.class="tags" href="/tags/ANDROID.html" title=android>android.com/apk/res/class="tags" href="/tags/ANDROID.html" title=android>android" class="tags" href="/tags/ANDROID.html" title=android>android:orientation="horizontal" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="fill_parent" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:gravity="center">
  <Button class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/play" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:text="@string/play" /> 
  <Button class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/stop" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:text="@string/stop" /> 
  </LinearLayout>
  <ImageView class="tags" href="/tags/ANDROID.html" title=android>android:id="@+id/anim" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_width="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:class="tags" href="/tags/LAYOUT.html" title=layout>layout_height="wrap_content" class="tags" href="/tags/ANDROID.html" title=android>android:background="@anim/girl" class="tags" href="/tags/ANDROID.html" title=android>android:scaleType="center" /> 
</LinearLayout>

主界面中两个按钮,一个用来播放动画,一个用来停止动画

class="language-java">package WangLi.Graphics.AnimationFrame;

import class="tags" href="/tags/ANDROID.html" title=android>android.app.Activity;
import class="tags" href="/tags/ANDROID.html" title=android>android.graphics.drawable.AnimationDrawable;
import class="tags" href="/tags/ANDROID.html" title=android>android.os.Bundle;
import class="tags" href="/tags/ANDROID.html" title=android>android.view.View;
import class="tags" href="/tags/ANDROID.html" title=android>android.view.View.OnClickListener;
import class="tags" href="/tags/ANDROID.html" title=android>android.widget.Button;
import class="tags" href="/tags/ANDROID.html" title=android>android.widget.ImageView;

public class AnimationFrame extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.class="tags" href="/tags/LAYOUT.html" title=layout>layout.main);
        //获取两个按钮
        Button play = (Button)findViewById(R.id.play);
        Button stop = (Button)findViewById(R.id.stop);
        ImageView imageView = (ImageView)findViewById(R.id.anim);
        //获取AnimationDrawable动画对象
        final AnimationDrawable anim = (AnimationDrawable)imageView.getBackground();
        play.setOnClickListener(new OnClickListener(){
        	public void onClick(View v)
        	{
        		anim.start();
        	}
        });
        stop.setOnClickListener(new OnClickListener(){
        	public void onClick(View v)
        	{
        		anim.stop();
        	}
        });
    }
}





http://www.niftyadmin.cn/n/1411364.html

相关文章

memset 与 memcpy

1. memset 需要的头文件 在C中 <string.h> 在C中 <cstring> 原型&#xff1a; void *memset(void *s, int ch, size_t n); 用法&#xff1a; memset是计算机中C/C语言函数。将s所指向的某一块内存中的前n个字节的内容全部设置为ch指定的ascii值&#xff0c; 第一…

初学Android,图形图像之在指定点(坐标)播放动画(三十五)

在指定地点播放动画&#xff0c;下面是一个爆炸过程的动画&#xff0c;鼠标点击处播放该动画定义动画资源文件blast.xml<?xml version"1.0" encoding"utf-8"?> <!-- 定义动画只播放一次&#xff0c;不循环 --> <animation-list xmlns:and…

Git 常用的几种处理大型二进制文件的组件

Git大文件存储&#xff08;Large File Storage&#xff0c;简称LFS&#xff09;的目标是更好地把“大型二进制文件&#xff0c;比如音频文件、数据集、图像和视频”集成到Git的工作流中。众所周知&#xff0c;Git在存储二 进制文件时效率不高&#xff0c;因为&#xff1a;Git默…

初学Android,图形图像之补间动画(三十六)

补间动画&#xff0c;开发人员只需指定开始&#xff0c;动画结束"关键帧"&#xff0c;而动画变化的"中间帧"由系统计算&#xff0c;并补齐&#xff0c;所以被称为补间动画 上面的例子就是这样&#xff0c;只是定义了动作&#xff0c;变化的帧都由Android自…

react-router-dom示例讲解(六)——未匹配(404页面)

react-router-dom的官方示例中&#xff0c;未匹配的示例也是一个比较简单的示例了。其核心就是Switch组件的匹配规则——仅仅匹配第一个符合条件的Route。 实现的效果图&#xff1a; 相关示例代码&#xff1a; import React, {Component} from react; import {BrowserRo…

初学Android,图形图像之混合使用逐帧动画和补间动画(三十七)

下面例子混合使用了逐帧动画和补间动画&#xff0c;还有一个缺点&#xff0c;就是画面闪烁&#xff0c;一直没有找到解决办法上面点击ImageView,上面的人物就开始走路跟移动 定义动画文件<?xml version"1.0" encoding"utf-8"?> <animation-list…

POJ 2800 Joseph’s Problem 数论找规律

Description 求 Input 两个整数n和k(1<n,k<1e9) Output 输出 Sample Input 5 3 Sample Output 7 暴力超时&#xff0c;这样就打下表找下余数的规律。输入100,27&#xff0c;一下子就可以看出来&#xff0c;倒着的看&#xff0c;是一段一段的等差序列。 例如100 25 除数 …

初学Android,图形图像之自定义补间动画(三十八)

Android提供Animation作为补间动画抽象基类&#xff0c;而且为该抽象基类提供了 AlphaAnimation,RotateAnimation,ScaleAnimation,TranslateAnimation四个类 但是在实际项目中&#xff0c;这些很可能不够用&#xff0c;可能需要一些更复杂的动画&#xff0c;比如说立体空间的旋…