简体   繁体   English

如何动画从中心 position 到全直径的波纹效果

[英]How to animate ripple effect from center position to full diameter

I am trying to create an image button effect using the ripple.我正在尝试使用波纹创建图像按钮效果。 I however want the ripple effect to start from the center of my image button icon and fill the image button.但是,我希望波纹效果从我的图像按钮图标的中心开始并填充图像按钮。 Is it possible to have the ripple effect animate from center to full circle.是否可以让涟漪效果从中心动画到整个圆圈。 Like a white circle animates in size from 0 to the diameter of the circle?就像一个白色圆圈的动画大小从 0 到圆圈的直径?

As it's stated in the documentation for the RippleDrawable you can set the anchoring point using setHotspot method.正如RippleDrawable的文档中所述,您可以使用setHotspot方法设置锚点。

By default View sets the hotspot to the current touch coordinates when pressed:默认情况下, View 将热点设置为按下时的当前触摸坐标:

private void setPressed(boolean pressed, float x, float y) {
        if (pressed) {
            drawableHotspotChanged(x, y);
        }

        setPressed(pressed);
    }

And ImageView passes this hotspot to its content: ImageView将此热点传递给其内容:

 public void drawableHotspotChanged(float x, float y) {
    super.drawableHotspotChanged(x, y);

    if (mDrawable != null) {
        mDrawable.setHotspot(x, y);
    }
}

So one way of getting the ripple effect starting from center is to extend ImageView and always set the hotspot to the center.因此,从中心开始获得涟漪效应的一种方法是扩展ImageView并始终将热点设置为中心。 There are other ways of course, eg one can try to extend RippleDrawable and override setHotspot there.当然还有其他方法,例如可以尝试扩展RippleDrawable并在那里覆盖setHotspot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM