首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android pop in animation

Android pop in animation
EN

Stack Overflow用户
提问于 2015-05-30 01:07:24
回答 3查看 12.8K关注 0票数 15

我在我的应用程序中有一个浮动的操作按钮,我想要弹出它,它是看不见的,开始增长到像60dp的大小,然后重新调整到56dp的正常大小。如何做到这一点?我知道如何在动画中做一个普通的淡入淡出,但不会弹出。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-05-30 01:28:37

我将在res/anim中创建一个动画文件,并使用顺序缩放动画,如下所示:

expand_in.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale 
        android:fromXScale="0.0" 
        android:fromYScale="0.0"
        android:toXScale="1.1" <!--set the scale value here-->
        android:toYScale="1.1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="400"/> <!--length of first animation-->


    <scale 
        android:fromXScale="1.1" <!--From whatever scale you set in the first animation-->
        android:fromYScale="1.1"
        android:toXScale="1.0" <!--Back to normal size-->
        android:toYScale="1.0"
        android:pivotX="50%" 
        android:pivotY="50%"
        android:startOffset="400" <!--start 2nd animation when first one ends-->
        android:duration="400"/>
</set>

然后在你的活动中:

代码语言:javascript
运行
复制
Animation expandIn = AnimationUtils.loadAnimation(this, R.anim.expand_in);
actionButton.startAnimation(expandIn);
票数 32
EN

Stack Overflow用户

发布于 2016-09-07 06:30:06

当我切换到使用过冲内插器时,我发现我的动画比目前接受的答案要流畅得多。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/overshoot_interpolator" >

<scale
    android:duration="700"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.0"
    android:toYScale="1.0" />

</set>

以下是一段视频,展示了插值器的示例:https://www.youtube.com/watch?v=OMOJxBe9KGg

这里是安卓文档中涉及到的地方:https://developer.android.com/guide/topics/resources/animation-resource.html#View

票数 12
EN

Stack Overflow用户

发布于 2018-09-26 21:55:22

我采用了最初的答案,但添加了额外的一层动画,以获得更好的流行效果。

代码语言:javascript
运行
复制
enter code here
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:duration="100"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.2"
    android:toYScale="1.2" />

<scale
    android:duration="100"
    android:fromXScale="1.2"
    android:fromYScale="1.2"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="100"
    android:toXScale="0.8"
    android:toYScale="0.8" />

<scale
    android:duration="100"
    android:fromXScale="0.8"
    android:fromYScale="0.8"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="100"
    android:toXScale="1.0"
    android:toYScale="1.0" />
</set>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30535304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档