【问题标题】:Android - custom button animationAndroid - 自定义按钮动画
【发布时间】:2015-05-04 23:12:12
【问题描述】:

我正在尝试为“投票”按钮创建动画,类似于您在 www.materialup.com 上可以找到的动画。 特别注意每个元素下面的“+1”或“like”按钮,它是一个圆形按钮,点击时会变成粉红色,同时一个小箭头会向上滑动,按钮内的数字会增加。 我或多或少地了解 android 的内部结构,但我在 UI 方面工作得更加紧张。这样的事情会有多难? 我已经定义了一个 FAB(浮动操作按钮)。我只是想知道如何完成动画部分。

这是我目前所拥有的:

fab_selector.xml

<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF27A7DA">
<item>
    <shape android:shape="oval">
        <solid android:color="#ff237da9" />
    </shape>
</item>

【问题讨论】:

    标签: android android-animation material-design


    【解决方案1】:

    研究使用ObjectAnimator 类。您使用静态 ofFloat 方法创建一个 ObjectAnimator 对象,并传入您希望设置动画的 View 对象,并定义应随时间变化的属性(位置、alpha、scaleX 等)。或者,对颜色使用 ofArgb 方法。

    Android Property Animation documentation 也应该有很大帮助。

    【讨论】:

    • 谢谢,但这似乎有点太复杂了,只是为了给你一点上下文,我什至无法在按钮中的数字顶部绘制三角形。我真的不太喜欢使用 XML
    • 如果你使用 ObjectAnimator,你不需要在 XML 中定义你的动画。您应该做的是创建视觉元素并使其看起来正确,然后对 alpha 或位置属性进行动画处理。
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2011-12-01
    • 2016-04-30
    • 2018-08-24
    • 2010-09-14
    • 1970-01-01
    • 2016-08-08
    • 2014-01-27
    相关资源
    最近更新 更多