【问题标题】:android system animation durationandroid系统动画时长
【发布时间】:2017-03-17 20:20:04
【问题描述】:

我只是想知道 android 系统动画(Activity A 切换到 Activity B 的动画)持续时间有多长,我该如何测量这个时间。我应该使用一些工具还是使用登录代码?

【问题讨论】:

    标签: android android-activity android-animation android-kernel


    【解决方案1】:

    活动或片段之间的系统动画时间由(在xml中)定义:

    @android:integer/config_activityShortDur
    @android:integer/config_activityDefaultDur
    

    或(在 Java 中):

    android.R.integer.config_activityShortDur
    android.R.integer.config_activityDefaultDur
    

    来源:

    <!-- The duration (in milliseconds) of a short animation. -->
    <integer name="config_shortAnimTime">200</integer>
    
    <!-- The duration (in milliseconds) of a medium-length animation. -->
    <integer name="config_mediumAnimTime">400</integer>
    
    <!-- The duration (in milliseconds) of a long animation. -->
    <integer name="config_longAnimTime">500</integer>
    
    <!-- The duration (in milliseconds) of the activity open/close and fragment open/close animations. -->
    <integer name="config_activityShortDur">150</integer>
    <integer name="config_activityDefaultDur">220</integer>
    

    【讨论】:

      【解决方案2】:

      您可以在 Android 中的 Settings -> Developer Options 下查看所有动画持续时间。这是用户偏好,这意味着您无法更改它。

      【讨论】:

        【解决方案3】:

        您可以在xml文件中添加动画持续时间

           android:duration="yourtime" 
        

        fade_in.xml

        <?xml version="1.0" encoding="utf-8"?>
        <alpha xmlns:android="http://schemas.android.com/apk/res/android"
               android:interpolator="@android:anim/accelerate_interpolator"
               android:fromAlpha="0.0" android:toAlpha="1.0"
               android:duration="200" />
        

        fade_out.xml

            <?xml version="1.0" encoding="utf-8"?>
            <alpha xmlns:android="http://schemas.android.com/apk/res/android"
               android:interpolator="@android:anim/accelerate_interpolator"
               android:fromAlpha="1.0" android:toAlpha="0.0"
               android:fillAfter="true"
               android:duration="200" />
        

        你可以这样调用

        Intent i = new Intent(this, NewActivity.class);
        startActivity(i);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        

        【讨论】:

        • 如果我不设置动画,android系统默认的持续时间是多少?
        • 没有动画为什么要设置活动之间的持续时间?
        • 因为android系统默认设置了系统动画
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-13
        • 2019-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-14
        相关资源
        最近更新 更多