android-animation - Android L "delightful"可绘制转换

标签 android-animation android-5.0-lollipop material-design

Google 是否允许使用图标 transitions such as these由开发者创建?还是开发人员有责任创建这种“令人愉快”的过渡?我真的很想在我的应用程序中实现这些。

Specifically icons like this

最佳答案

您可以使用 AnimatedDrawable 和基于位图的帧创建动画图标。在 L 上,您可以使用 AnimatedStateListDrawable 来创建有状态的动画(例如复选框动画)。

这是一个 AnimatedDrawable 示例(实际上这是 L 预览上复选框的实现),使用可以从代码启动和停止的 15 毫秒长帧:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:duration="15" android:drawable="@drawable/my_icon_frame_000" />
    ...additional frames...
</animation-list>

这是一个 AnimatedStateListDrawable 使用 AnimatedDrawable 转换来实现复选框动画,该动画根据 View 状态自动启动和停止:

<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:state_checked="true">
        <bitmap android:src="@drawable/btn_check_to_on_mtrl_015" android:tint="?attr/colorControlActivated" android:alpha="?attr/disabledAlpha" />
    </item>
    <item android:state_enabled="false">
        <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" android:alpha="?attr/disabledAlpha" />
    </item>
    <item android:state_checked="true" android:id="@+id/on">
        <bitmap android:src="@drawable/btn_check_to_on_mtrl_015" android:tint="?attr/colorControlActivated" />
    </item>
    <item android:id="@+id/off">
        <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" />
    </item>
    <transition android:fromId="@+id/off" android:toId="@+id/on">
        <animation-list>
            <item android:duration="15">
                <bitmap android:src="@drawable/btn_check_to_on_mtrl_000" android:tint="?attr/colorControlNormal" />
            </item>
            ...additional frames...
        </animation-list>
    </transition>
    <transition android:fromId="@+id/on" android:toId="@+id/off">
        <animation-list>
            <item android:duration="15">
                <bitmap android:src="@drawable/btn_check_to_off_mtrl_000" android:tint="?attr/colorControlActivated" />
            </item>
            ...additional frames...
        </animation-list>
    </transition>
</animated-selector>

关于android-animation - Android L "delightful"可绘制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25371958/

相关文章:

Android 托管配置文件 - 配置文件所有者无法设置用户限制 no_add_user

android - 使用 Android L 和 Camera2 API 处理相机预览图像数据

Android 从路径加载库

javascript - Material Design 图标按钮无法正常工作

android - 扩展持久性 Bottom Sheet 时调整回收器 View 高度

android - Cardview不可去除的灰色下划线(Android 4.0.4设备)

java - 在 Android 上动画约束布局更改的最佳方式

android - 我在 Android 动画中得到 NullPointerException?

android - 卷页动画 - 问题

android - 动画监听器不适用于按钮单击