是否有可能在按钮上使用Shine或Glint Movers Animation进行编码?(不是GIF或类似方式)



我想在上面有一个带有光泽或闪烁动画动画的按钮。只是复杂的只是一个按钮上的移动光线。在Android Studio中的Java中使用动画吗?

是否有可能

有很多方法做到这一点,但我会提供我经常使用的方法...

用水平和垂直线梯度创建形状...

vert_line.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient
        android:angle="0"
        android:endColor="#555994"
        android:centerColor="#ffffff"
        android:startColor="#555994"
        android:type="linear" />
    <corners
        android:radius="0dp"/>
</shape>

hor_line.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient
        android:angle="90"
        android:endColor="#555994"
        android:centerColor="#ffffff"
        android:startColor="#555994"
        android:type="linear" />
    <corners
        android:radius="0dp"/>
</shape>

然后创建一个选择器,以在按下按钮时进行背景更改,并会给您带来闪亮效果...

shine_line.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/line_vert" /> <!-- pressed -->
    <item android:drawable="@drawable/line_hor" /> <!-- default -->
</selector>

上一次将其设置为您的按钮背景。

   <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shine_line"/>

它将像魅力一样工作。

相关内容

最新更新