- 浏览: 46510 次
- 性别:
- 来自: 西安
最新评论
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 1428Android Intent and Intent ... -
Intent详解
2011-03-03 14:18 1116在应用中,我们可以以两种形式来使用Intent: 直接I ... -
Intent间传送数据一般有两种常用方法
2011-01-24 14:50 1269Intent间传送数据一般有两种常用的办法: 1.extra ... -
android RelativeLayout 详解
2011-01-01 09:46 1561<?xml version="1.0" ... -
How to Use Android Downloads Provider
2010-12-20 21:41 1307本文转载自 http://blog.lytsing.or ... -
android 开发中的一些小知识点
2010-12-17 09:49 9641 关于onPause(): onPause ... -
content provider 深入解析
2010-12-15 22:04 1067Content providers are on ... -
Service的高级应用
2010-12-12 20:48 1323下面是android Service的高级应用的一个例子,主要 ... -
TabActivity
2010-12-12 19:09 1733下面是一个使用android tabactivity 的例子 ... -
android 测试初探(android test)
2010-12-07 15:00 7986android Testing and Instrumenta ... -
Localization of android
2010-12-05 21:51 0android 会在不同地域的不同机器上运行。为了是应用能够 ... -
android高效编程之使用本地变量
2010-12-05 14:26 948hava a look at the following co ... -
在不同的Activity中传递对象的方法
2010-12-02 10:20 1980下面我们将要实现的功 ... -
Cursor与Adapter
2010-11-21 08:34 1203来自: http://hi.baidu.com/lfcaoli ... -
Working with Context Menus
2010-11-15 23:36 828... -
Handler的理解
2010-11-14 20:58 801A Handler allows you to sen ... -
android开发问题解决日志
2010-11-14 18:33 18461.、android中R文件消失的处理方式 ... -
android 中对SDCard 的操作
2010-11-11 14:14 1599对于像视频这样的大文件,我们可以把它存放在SDCard。 SD ... -
android高效的编写高效代码
2010-10-17 19:13 729本文来源于: 从此学习网 原文: http://www.con ... -
scale animation
2010-10-11 23:29 1583Scale animation: You use this t ...
相关推荐
参考 View Animation 效果
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 ...
我的博客《Android动画之二:View Animation》附带源码
基本的太阳地球月亮模型,地球围绕太阳转,月球围绕地球转
主要为大家详细介绍了Android使用View Animation实现动画加载界面的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
安卓Android源码——View中添加Animation.zip
View Animation / 视图动画 English explanation can go to read this article Ⅱ. Drawable Animation / 帧动画 / Frame 动画 English explanation can go to read this article Ⅲ. Property Animation / 属性...
android view animation
View Animation 也是指此动画。属性动画:.支持对所有View能更新的属性的动画(需要属性的setXxx()和getXxx()); 更改的是View实际的属性,所以不会影响其在动画执行后所在位置的正常使用; Android3.0 (API11)及...
ViewAnimation This is a library of the AnimatorSet,it has three move path and many animation,you can make a easy animation of view by youself. animation of View i did not finish it at this time ...
参考 Android动画学习Demo(1) 关于ViewAnimation的用法及总结
* View Animation:最早提供的一种动画,用来这只view。 * Drawable Animation:帧动画,一个一个的展示Drawable的resources,就像放幻灯片一样。 * Property Animation :属性动画只对Android 3.0(API 11)以上...
Android提供了几种动画类型:View Animation 、Drawable Animation 、Property Animation 。View Animation相当简单,不过只能支持简单的缩放、平移、旋转、透明度基本的动画,且有一定的局限性。比如:你希望View有...
// [self viewAnimation]; //View的动画 // [self imgToGrayimg]; //UIImage转为灰度图 // [self scaleFromScaledToSize:CGSizeMake(100, 100)]; //图像压缩 // [self SwipeViewAnimation]; //弹出动画 // [self ...
5、如果一切正常,那么可以分别看到帧动画(frame-by-frame)、布局动画(layout animation)和视图动画(view animation) 目的:动画效果可以让用户的体验感非常好。在“演示Android中的文字和图片特效控件的使用”资源...
New iOS 7 topics covered include asset catalogs, snapshots, template images, keyframe and spring view animation, motion effects, tint color, fullscreen views and bar underlapping, background ...
ViewAnimation Tweened Animations学习
android 动画 简单使用 property animation view animation(tween animation)drawable animation(frame animation)
ViewAnimation(TweenAnimation):补间动画,给出两个关键帧,通过一些算法将给定属性值在给定的时间内在两个关键帧间渐变。Viewanimation只能应用于View对象,而且只支持一部分属性,如支持缩放旋转而不支持背景...