Android同心圆展开渐变动画
Android animation of concentric expanding fading circles
在 Android 中,我正在寻找尽可能简单的 "built-in" 方法来创建一个可绘制的或自定义的视图,以动画化 4 个半径缓慢扩展的同心圆。
从哪里开始最好?
是否可以在纯 XML 中执行此操作?
如果没有,可以使用单层可绘制对象来完成,还是应该使用多层可绘制对象?
谢谢!
最好的起点是 this repository。这是 Android
的易于配置的波纹背景动画。插上电源,您就可以开始使用了。以下是步骤:
要在安装后进行设置,请像这样将 RippleBackground
添加到您的布局中,
<com.skyfishjy.library.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:id="@+id/centerImage"
android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>
然后你就可以像这样覆盖onClick方法来启动动画了,
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content);
ImageView imageView=(ImageView)findViewById(R.id.centerImage);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rippleBackground.startRippleAnimation();
}
});
调用方法rippleBackground.stopRippleAnimation()
停止动画。
希望对您有所帮助。
在 Android 中,我正在寻找尽可能简单的 "built-in" 方法来创建一个可绘制的或自定义的视图,以动画化 4 个半径缓慢扩展的同心圆。
从哪里开始最好?
是否可以在纯 XML 中执行此操作?
如果没有,可以使用单层可绘制对象来完成,还是应该使用多层可绘制对象?
谢谢!
最好的起点是 this repository。这是 Android
的易于配置的波纹背景动画。插上电源,您就可以开始使用了。以下是步骤:
要在安装后进行设置,请像这样将 RippleBackground
添加到您的布局中,
<com.skyfishjy.library.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:id="@+id/centerImage"
android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>
然后你就可以像这样覆盖onClick方法来启动动画了,
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content);
ImageView imageView=(ImageView)findViewById(R.id.centerImage);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rippleBackground.startRippleAnimation();
}
});
调用方法rippleBackground.stopRippleAnimation()
停止动画。
希望对您有所帮助。