如何创建自定义视图缩放动画效果 [英] How to create zoom animation effect for custom view

查看:517
本文介绍了如何创建自定义视图缩放动画效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有重新presents饼图自定义视图。

Currently, I have a custom view which represents a pie chart.

public class PieChart extends View {
    @Override
    protected void onDraw(Canvas canvas) {

通过以​​下布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    ... >

    <org.yccheok.jstock.gui.charting.PieChart

它看起来像这样(定制饼图的观点是上半部分来看,它的宽度是FILL_PARENT,它的高度是母公司的50%)

It looks like this (The custom pie chart view is the top half view, which its width is fill_parent, and its height is 50% of parent)

在正在启动的活动,我很期待有一个类似的饼图缩放动画

When the activity being launched, I'm looking forward to have a pie chart zoom animation similar to this

http://www.youtube.com/watch?v=uwGoSswCZhQ

我读过的http://东西.mit.edu / AFS / sipb /项目/安卓/文档/培训/动漫/ zoom.html 。这个例子是使用2图像(一个缩小版本,另一种是扩大版)要达到这样的效果。

I had read http://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/zoom.html. The example is using 2 images (one is scale down version, another is scaled up version) to achieve such effect.

我不完全知道我怎么可以应用它们在我的情况?我是否需要兴建第2版饼图呢? (一个是缩小版,另一种是正常大小的版本)

推荐答案

您可以使用好老 ScaleAnimation 来达到这种效果。这里是缩放的图从20%至100%的例子。规模原点被设置为视图的中心。

You can use the good old ScaleAnimation to achieve this effect. Here is an example which scales a view from 20% to 100%. The scale origin is set to the center of the view.

ScaleAnimation scaleAnimation = new ScaleAnimation(0.2f, 1f, 0.2f, 1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
        ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(600);
pieChart.startAnimation(set);

请参阅 http://developer.android.com/reference/android /view/animation/ScaleAnimation.html 获取完整的文档。

See http://developer.android.com/reference/android/view/animation/ScaleAnimation.html for the full documentation.

这篇关于如何创建自定义视图缩放动画效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆