0

キャンバスを使ってメーター以下を実現したい。

ここに画像の説明を入力

ご覧のとおり、黒い部分には 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

この ShapeDrawable を shaderfactory で見てください

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 に答える