android动画例子,android动画的例子

Android为动画开发提供了大量的类和接口。大多数类和接口在android.animation包中提供。

Android动画使你可以在运行时更改对象属性和行为。有多种方法可以在android中制作动画。

AnimationDrawable类提供了开始和结束动画的方法。甚至,你也可以使用基于时间的动画。

让我们看一下android动画的简单示例。

activity_main.xml

你只需要查看。

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

/>

仅具有图像视图。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/anm"

>

MainActivity类

package com.srcmini.animation;

import android.os.Bundle;

import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.widget.ImageView;

public class MainActivity extends Activity {

ImageView anm;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.logo);

anm = (ImageView)findViewById(R.id.anm);

anm.setBackgroundResource(R.drawable.animation);

// the frame-by-frame animation defined as a xml file within the drawable folder

/*

* NOTE: It's not possible to start the animation during the onCreate.

*/

}

public void onWindowFocusChanged (boolean hasFocus) {

super.onWindowFocusChanged(hasFocus);

AnimationDrawable frameAnimation =

(AnimationDrawable) anm.getBackground();

if(hasFocus) {

frameAnimation.start();

} else {

frameAnimation.stop();

}

}

}

你需要在res / drawable-hdpi目录中创建animation.xml文件。

你需要有很多图像。在这里,我们使用14张图像,所有14张图像都位于res / drawable-mdpi目录中。

android:oneshot="false">

输出:

31ca180448bed7c9664155e9cd54ac1a.png

d1ed673edada230b387613071e191ce4.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值