0

我想通过使用 canvas 达到米以下。

在此处输入图像描述

如您所见,黑色部分有 2 种颜色。我可以使用可绘制的形状设置黑色运动图像的颜色。到目前为止我已经实现的代码和图像如下所示。我怎样才能得到想要的结果。我是画布新手。

在此处输入图像描述

    float[] outerR = new float[] { 7, 7,curve , curve, curve, curve, 7, 7};
    ShapeDrawable mMovingRectangle = new ShapeDrawable();
    mMovingRectangle.setShape(new RoundRectShape(outerR, null, null));
    mMovingRectangle.getPaint().setColor(getResources().getColor(R.color.black_alfa_60));
4

1 回答 1

0

用shaderfactory看看这个ShapeDrawable

private void FillCustomGradient(View v) {
    final View view = v;
    Drawable[] layers = new Drawable[1];

    ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient lg = new LinearGradient(
                    0,
                    0,
                    0,
                    view.getHeight(),
                    new int[] {
                             getResources().getColor(R.color.color1), // please input your color from resource for color-1,2,3,4
                             getResources().getColor(R.color.color2),
                             getResources().getColor(R.color.color3),
                             getResources().getColor(R.color.color4)},
                    new float[] { 0, 0.49f, 0.50f, 1 },
                    Shader.TileMode.CLAMP);
            return lg;
        }
    };
    PaintDrawable p = new PaintDrawable();
    p.setShape(new RectShape());
    p.setShaderFactory(sf);
    p.setCornerRadii(new float[] { 5, 5, 5, 5, 0, 0, 0, 0 });
    layers[0] = (Drawable) p;

    LayerDrawable composite = new LayerDrawable(layers);
    view.setBackgroundDrawable(composite);
}

可能这对你有帮助

于 2015-05-15T05:47:40.013 回答