我的视图如下所示
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:background="@drawable/ripple"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
而ripple.xml则是
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight" >
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
一切都很顺利。当我触摸视图时,它会产生涟漪效果。 我想要的是从代码中重复启动视图上的涟漪动画,以将其显示为不确定进度。使波纹持续不断地扩散。
类似于:
Runnable runnable = new Runnable() {
@Override
public void run() {
RippleDrawable drawable = (RippleDrawable) button.getBackground();
drawable.showRipples(true, true); // <-- This is needed
handler.postDelayed(runnable, 500);
}
};
如何做到这一点?