有个小需求,给按钮加一个灯光划过的效果,这样的需求一般有UI,肯定就找UI了要个gif图不就完事了,可是这次没有,好久自己做一个嘛。Web端的大佬实现很快,到安卓这边呢,百度一搜发现诶?怎么没有,好吧自己来一个
一切动效相关的不给图看都是耍流氓
所以俺不能这么干啊,OK!直接上效果图,再来解释下怎么实现的
效果就是这样子,怎么实现呢?
从图分析下,就是一个光斜着从左边移动要右边循环嘛,这有啥难的??
来看一看我的第一版,第二版
这是个什么👻?一点都不像啊?
赶紧再问了问Web端大佬,噢,加了一个矩阵转换,我们也加上
关于图像矩阵Matrix单独再出一期解释
上最后成果代码:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:clipChildren="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/inviteFriendsBtn_now