问题描述
我想制作一个类似材质波纹动画的动画,所以我决定看一下它的源代码。
-
输入点是:
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" />
-
接下来我们进入Android\Sdk\platforms\android-30\data\res\values\themes.xml
<item name="selectableItemBackground">@drawable/item_background</item>
没什么特别的,只是另一个drawable。
- 下一步: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
- 我们很接近,在这个文件中我们看到了不同状态的可绘制对象。转换文件位于: 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 个文件,如下图
所以问题是:
- 这 4 个方块是如何变成圆形波纹动画的?
- 这意味着这个黑色指针?
- 橙色填充和绿色边框有什么作用?
- (可选)神奇的部分在哪里?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)