- 浏览: 47630 次
- 性别:
- 来自: 西安
最新评论
view animation 的实现
Understanding View Animation
When a view is displayed on a presentation surface in Android, it goes through a
transformation matrix. In graphics applications, you use transformation matrices to
transform a view in some way. The process involves taking the input set of pixel
coordinates and color combinations and translating them into a new set of pixel
coordinates and color combinations. At the end of a transformation, you will see an
altered picture in terms of size, position, orientation, or color.
You can achieve all of these transformations mathematically by taking the input set of
coordinates and multiplying them in some manner using a transformation matrix to arrive
at a new set of coordinates. By changing the transformation matrix, you can impact how
a view will look. A matrix that doesn’t change the view when you multiply it is called an
identity matrix. You typically start with an identity matrix and apply a series of
transformations involving size, position, and orientation. You then take the final matrix
and use that matrix to draw the view.
view Animation 本质是view利用一个Animation的类(或是子类)实现动画的效果。而Animation是通过修改view的
transformation matrices,来达到控制view的行为的目的。
本例是先实现一个ViewAnimation的类,重写了Animation的一些必要的方法,来实现一个ListView 的动画效果。
当然这个Animation必须现在ListView上注册才行,利用 listView.startAnimation(new ViewAnimation())就行了。
/**
*
*/
package hust.ophoneclub.ViewAnimation;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
/**
* @author chenhao
*
*/
public class ViewAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final Matrix matirx = t.getMatrix();
matirx.setScale(interpolatedTime, interpolatedTime);
super.applyTransformation(interpolatedTime, t);
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
// Initialize this animation with the dimensions of the object being
// animated as well as the objects parents. (This is to support animation
// sizes being specifed relative to these dimensions.)
super.initialize(width, height, parentWidth, parentHeight);
setDuration(2500); //动画持续的时间
setFillAfter(true); //动画最终的状态
setInterpolator(new LinearInterpolator());//定义动画的布局形式
}
}
下面是展示这个动画的Activity。
package hust.ophoneclub.ViewAnimation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class ViewAnimationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupListItem();
setupButton();
}
/**
*
*/
private void setupButton() {
Button btn = (Button)findViewById(R.id.button_id);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animateListView();
}
});
}
/**
*
*/
private void setupListItem() {
String[] listItem = new String[]{
"item 1", "item 2", "item 3",
"item 4", "item 5", "item 6"
};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, listItem);
getListVIew().setAdapter(arrayAdapter);
}
/**
* @return
*/
private ListView getListVIew() {
ListView listView = (ListView)findViewById(R.id.list_view_id);
return listView;
}
private void animateListView() {
//在listView上注册这个Animation
getListVIew().startAnimation(new ViewAnimation());
}
}
下面是这个Activity的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id = "@+id/button_id"
android:layout_width = "fill_parent"
android:layout_height ="wrap_content"
android:text = "Start animation"
/>
<ListView
android:id = "@+id/list_view_id"
android:layout_width="fill_parent"
android:persistentDrawingCache = "scrolling|animation"
android:layout_height="fill_parent"
/>
</LinearLayout>
实现的效果如下。
首先运行程序
点击 “StartAnimation”之后开始动画。 这个listView从左上角开始一直增大,直到回到初始状态。
发表评论
-
Android Intent and Intent Filter (转)
2011-03-10 22:47 1458Android Intent and Intent ... -
Intent详解
2011-03-03 14:18 1140在应用中,我们可以以两种形式来使用Intent: 直接I ... -
Intent间传送数据一般有两种常用方法
2011-01-24 14:50 1305Intent间传送数据一般有两种常用的办法: 1.extra ... -
android RelativeLayout 详解
2011-01-01 09:46 1579<?xml version="1.0" ... -
How to Use Android Downloads Provider
2010-12-20 21:41 1330本文转载自 http://blog.lytsing.or ... -
android 开发中的一些小知识点
2010-12-17 09:49 9991 关于onPause(): onPause ... -
content provider 深入解析
2010-12-15 22:04 1098Content providers are on ... -
Service的高级应用
2010-12-12 20:48 1355下面是android Service的高级应用的一个例子,主要 ... -
TabActivity
2010-12-12 19:09 1771下面是一个使用android tabactivity 的例子 ... -
android 测试初探(android test)
2010-12-07 15:00 8014android Testing and Instrumenta ... -
Localization of android
2010-12-05 21:51 0android 会在不同地域的不同机器上运行。为了是应用能够 ... -
android高效编程之使用本地变量
2010-12-05 14:26 975hava a look at the following co ... -
在不同的Activity中传递对象的方法
2010-12-02 10:20 2011下面我们将要实现的功 ... -
Cursor与Adapter
2010-11-21 08:34 1226来自: http://hi.baidu.com/lfcaoli ... -
Working with Context Menus
2010-11-15 23:36 860... -
Handler的理解
2010-11-14 20:58 836A Handler allows you to sen ... -
android开发问题解决日志
2010-11-14 18:33 18791.、android中R文件消失的处理方式 ... -
android 中对SDCard 的操作
2010-11-11 14:14 1636对于像视频这样的大文件,我们可以把它存放在SDCard。 SD ... -
android高效的编写高效代码
2010-10-17 19:13 787本文来源于: 从此学习网 原文: http://www.con ... -
scale animation
2010-10-11 23:29 1610Scale animation: You use this t ...
相关推荐
**Android 动画详解:深入理解View Animation** 在Android开发中,动画是提升用户体验的关键因素之一,能够使应用更加生动和吸引人。本篇将详细探讨Android中的View Animation,它是Android早期提供的动画机制,...
"View Animation Demo 源代码"是一个典型的Android项目,展示了如何利用视图动画(View Animation)来实现各种动态效果,如旋转、缩放等。这个源代码提供了很好的学习资源,帮助开发者理解和实践Android中的基本动画...
View Animation Only animate View objects If animate non-view objects, you have to implement your own code takes less time to setup and requires less code to write Drawable Animation Load drawable ...
本文将深入探讨两种主要的动画类型:帧动画(Drawable Animation)和补间动画(View Animation),并以一个简单的“太阳地球月亮”模型为例,来阐述这两种动画的实现原理和应用场景。 ### 帧动画 (Drawable ...
本资源包"安卓Android源码——View中添加Animation.zip"主要关注如何在Android的View组件中应用动画效果。接下来,我们将深入探讨Android视图动画的实现原理及其在实际开发中的应用。 一、Android动画类型 1. **帧...
Android View Animation实现动画加载界面 Android View Animation是Android系统中的一种动画实现方式,通过使用View Animation,可以实现不同的动画效果,例如旋转、缩放、平移等。下面是使用View Animation实现...
这个压缩包“Android源码——View中添加Animation.zip”包含了关于在Android的View中如何添加动画的详细资源,包括一个图片示例(1-1209122202530-L.png)、源码说明文本(源码说明.txt)、以及一个链接到更多源码的...
`View`中的动画主要分为两种类型:属性动画(Property Animation)和视图动画(View Animation)。本压缩包"Android代码-View中添加Animation.zip"可能包含了如何在Android应用的`View`中添加这两种动画的相关代码...
主要有两种类型的动画:Property Animation(API 11+)和View Animation(API 1+)。在这个例子中,我们可能使用的是View Animation,因为SurfaceView通常需要兼容低版本Android设备。 1. **定义Animation** 创建...
"android-view-animation抖动shake"这个话题主要涉及到了Android视图动画中的shake效果,这是一种常见的错误提示或吸引用户注意力的动画方式,比如当用户输入错误时,可以令编辑框(EditText)进行抖动来提示。...
Android Tween Animation分为两种主要类型:Property Animation和View Animation。Property Animation是Android 3.0(API Level 11)引入的新特性,它可以对对象的任何属性进行动画处理,而不仅仅是View。然而,View...
本资料“Android View中添加Animation.zip”显然聚焦于如何在Android的View组件上应用各种动画效果。以下是关于Android View动画的详细阐述: 1. **基本概念** - **Animation**:Android中的动画主要分为两种类型...
本篇将详细探讨Android中的动画技术,包括属性动画(Property Animation)、视图动画(View Animation)以及过渡动画(Transition Animation)。 **属性动画(Property Animation)** 属性动画系统是Android 3.0...
Android动画主要包括两种类型:属性动画(Property Animation)和视图动画(View Animation)。视图动画是早期Android版本中的动画系统,主要通过改变视图的位置、大小、透明度等属性来模拟动画效果,但并不真正改变...
本文将深入探讨Android中的动画技术,包括`Animation`、`PropertyAnimation`、`ViewAnimation`以及`DrawableAnim`。 首先,我们来了解Android的基础动画系统,即`Animation`类。`Animation`类是所有动画的基类,它...
本资源"Android View中添加Animation.rar"主要探讨如何在Android的View组件中应用动画。通过学习这些内容,开发者可以更好地掌握Android动画机制,为应用程序增添动态美感。 首先,Android提供了两种主要的动画类型...
Android Animation主要包括三种类型的动画:Property Animation、View Animation和Transition Animation。在本示例中,我们主要关注的是View Animation,它是早期版本(API Level 8及以下)中的动画机制,主要通过...
Android提供了多种动画机制,包括属性动画(Property Animation)、视图动画(View Animation)和框架动画(Frame Animation)。这篇博客文章“andorid animation”可能深入探讨了这些主题,并结合源码分析和实用...
在Android程序开发中,View动画(Animation)是一个关键部分,用于增强用户界面的交互性和视觉效果。本资源“Android程序研发源码Android View中添加Animation.zip”提供了关于如何在Android View上实现动画的源代码...