安卓系统动画持续时间

4

我想知道安卓系统动画(Activity A 切换到 Activity B 的动画)持续多长时间,以及如何测量这个时间。我应该使用一些工具还是在代码中使用日志记录?

3个回答

3
系统中活动或片段之间的动画时间由以下方式定义(在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>

1
您可以在Android的“设置” ->“开发者选项”下检查所有动画持续时间。这是用户偏好,意味着您无法更改它。 在此输入图片描述

1
您可以在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操作系统中默认的持续时间是多久? - Shuai Wang
为什么要在活动之间设置持续时间,与动画无关? - sasikumar
因为Android操作系统默认设置了系统动画。 - Shuai Wang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接