Android涟漪动画的理解

问题描述

我想制作一个类似材质波纹动画的动画,所以我决定看一下它的源代码

  1. 输入点是: android:background="?android:attr/selectableItemBackground"> 转到:Android\Sdk\platforms\android-30\data\res\values\attrs.xml

     <!-- Background drawable for bordered standalone items that need focus/pressed states. -->
     <attr name="selectableItemBackground" format="reference" />
    
  2. 接下来我们进入Android\Sdk\platforms\android-30\data\res\values\themes.xml

    <item name="selectableItemBackground">@drawable/item_background</item>

没什么特别的,只是另一个drawable。

  1. 下一步:Android\Sdk\platforms\android-30\data\res\drawable\item_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false" android:drawable="@color/transparent" />

    <!-- Even though these two point to the same resource,have two states so the drawable will  invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/list_selector_background_focused" />
    <item android:drawable="@color/transparent" />

</selector

  1. 我们很接近,在这文件中我们看到了不同状态的可绘制对象。转换文件位于: Android\Sdk\platforms\android-30\data\res\drawable\list_selector_background_transition.xml 是:
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:drawable/list_selector_background_pressed"  />
    <item android:drawable="@android:drawable/list_selector_background_longpress"  />
</transition>

最后我们有 4 个文件,如下图

enter image description here

所以问题是:

  1. 这 4 个方块是如何变成圆形波纹动画的?
  2. 这意味着这个黑色指针?
  3. 橙色填充和绿色边框有什么作用?
  4. (可选)神奇的部分在哪里?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)