涟漪效应方向问题

Ripple Effect direction issue

当我触摸我的布局(以 RippleDrawable 作为背景的线性布局)的边界时,涟漪效果不是从点击的点开始,而是在 波纹也传播到中心。

RippleDrawable drawable = new RippleDrawable(ColorStateList.valueOf(pressedColor), null, getRippleMask(baseColor)); this.setBackground(drawable);

我也试过用setHotspot的方法,用as坐标(0,0)也没有从左上角开始。

试试这个方法可能对你有用

private void startRippleAnimation(View v, float x, float y){
   Drawable background = v.getBackground();
   if(background instanceof RippleDrawable){
     RippleDrawable ripple = (RippleDrawable)background;
     ripple.setHotspot(x, y);
     ripple.setVisible (true, true);
   }

}

setHotspot(x,y)

之前使用方法setHotspotBound(x,y,x,y)解决了