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();
为了 KOTLIN
val rippleBackground = findViewById(R.id.content) as RippleBackground
val imageView: ImageView = findViewById(R.id.centerImage) as ImageView
imageView.setOnClickListener(object : OnClickListener() {
fun onClick(view: View?) {
rippleBackground.startRippleAnimation()
}
})
<?xml version="1.0" encoding="utf-8"?>
<!--this ripple animation only working for >= android version 21 -->
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/click_efect" />