Android的:如何扩大和缩小视图斜? [英] Android: How to expand and shrink a view diagonally?

查看:165
本文介绍了Android的:如何扩大和缩小视图斜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动画的视图的膨胀收缩回初始大小。我试着用动画集添加两个动画,使得第二个动画将在第一个动画之后开始,但无法得到它的工作。

I am trying to animate a view which expands and shrinks back to the initial size. I tried using animation set to add two animations so that the second animation will start after the first animation but was not able to get it working.

AnimationSet expandAndShrink = new AnimationSet(true);
ScaleAnimation expand = new ScaleAnimation(
     1f, 1.5f, 
     1f, 1.5f,
     Animation.RELATIVE_TO_PARENT, 0,
     Animation.RELATIVE_TO_PARENT, 0);

ScaleAnimation shrink = new ScaleAnimation(
     1.5f, 1f, 
     1.5f, 1f,
     Animation.RELATIVE_TO_PARENT, 1f,
     Animation.RELATIVE_TO_PARENT, 1f);

expandAndShrink.addAnimation(expand);
expandAndShrink.addAnimation(shrink)
expandAndShrink.setFillAfter(true);
expandAndShrink.setDuration(1000);
expandAndShrink.setInterpolator(new AccelerateInterpolator(1.0f));

view.bringToFront();
view.startAnimation(expandAndShrink);

我真的AP preciate任何帮助,得到它的工作。在此先感谢

I really appreciate any help to get it working. Thanks in advance

推荐答案

我有固定的扩张和收缩动画和持续时间增加两个。你也应该补充shrink.setStartOffset(1000);所以第二个动画起步较晚

I have fixed "expand" and "shrink" animations, and added durations for both. Also you should add shrink.setStartOffset(1000); so second animation starts later

    AnimationSet expandAndShrink = new AnimationSet(true);
    ScaleAnimation expand = new ScaleAnimation(
         1f, 1.5f, 
         1f, 1.5f,
         Animation.RELATIVE_TO_PARENT, 0,
         Animation.RELATIVE_TO_PARENT, 0);
    expand.setDuration(1000);

    ScaleAnimation shrink = new ScaleAnimation(
         1.5f, 1f, 
         1.5f, 1f,
         Animation.RELATIVE_TO_PARENT, 0f,
         Animation.RELATIVE_TO_PARENT, 0f);
    shrink.setStartOffset(1000);
    shrink.setDuration(1000);

    expandAndShrink.addAnimation(expand);
    expandAndShrink.addAnimation(shrink);
    expandAndShrink.setFillAfter(true);
    expandAndShrink.setInterpolator(new AccelerateInterpolator(1.0f));

    view.startAnimation(expandAndShrink);

这篇关于Android的:如何扩大和缩小视图斜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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