透明蒙层

1. 滑出阴影

SlideAnimationProvider.java
private void drawShadowVertical(Canvas canvas, int top, int bottom, int dX) {
    final GradientDrawable.Orientation orientation = dX > 0 ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT;
    final int[] colors = new int[]{0x20000000, 0x00000000};
    final GradientDrawable gradient = new GradientDrawable(orientation, colors);
    gradient.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    gradient.setDither(true);
    if (dX > 0) {
        gradient.setBounds(dX - 48, top, dX, bottom);
    } else {
        gradient.setBounds(myWidth + dX, top, myWidth + dX + 48, bottom);
    }
    gradient.draw(canvas);
}

滑动动画中的拖尾的宽度只能通过硬编码的方式设置,本例中拖尾阴影的宽度为 48。

Last updated

Was this helpful?