Android L“令人愉快"可绘制的变换 [英] Android L "delightful" drawable transformations

查看:56
本文介绍了Android L“令人愉快"可绘制的变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google是否允许图标转换例如由开发人员创建的这些?还是开发人员有责任创建这种令人愉快的"过渡?我真的很想在我的应用程序中实现这些功能.

Does Google allow for icon transitions such as these to be created by the developer? Or is it the developers responsibility to create such "delightful" transitions? I'd really like to implement these in my app.

像这样的图标

推荐答案

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

You can create an animated icon using AnimatedDrawable and bitmap-based frames. On L, you can use AnimatedStateListDrawable to create stateful animations (such as the check box animation).

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

Here is an AnimatedDrawable example (actually this is the implementation for the check box on L preview) using 15ms-long frames that can be started and stopped from code:

<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过渡来实现一个复选框动画,该动画根据视图状态自动启动和停止:

And here is an AnimatedStateListDrawable using AnimatedDrawable transitions to implement a check box animation that starts and stops automatically based on View state:

<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 L“令人愉快"可绘制的变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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