0

グラフィックキャンバス、カラー、ペイントクラスを使用して、Android で長方形を描画しています。四角形をそれぞれに色を付けて配列に格納している場合、端から端まで色のグラデーションをどのように持たせますか? Color.red(colorInt) などを使用して RGB 値を変更しようとしましたが、奇妙な結果が得られます。

編集:各長方形自体にはグラデーションがありません。それぞれが無地である必要があります。四角形が配列内のどこにあるかに基づいて、各色成分に重みを掛けてみましたが、効果がありません。

これが私が試したコードの一部です。

if(lt != null && rt != null)
{
    int r = (int) ((Color.red(lt.getColor()) * (1.0 - weight)) - (Color.red(rt.getColor()) * weight));
    int g = (int) ((Color.green(lt.getColor()) * (1.0 - weight)) - (Color.green(rt.getColor()) * weight));
    int b = (int) ((Color.blue(lt.getColor()) * (1.0 - weight)) - (Color.blue(rt.getColor()) * weight));

    color = Color.argb(ALPHA, r, g, b);
}
4

1 に答える 1

0

これはあなたの質問に対する正確な答えではないかもしれませんが、グラデーションを 1 つのビューに設定するのに役立つかもしれません:

View yourView = findViewById(R.id.mainlayout);

GradientDrawable gd = new GradientDrawable(
        GradientDrawable.Orientation.TOP_BOTTOM,
        new int[] {0xFF616261,0xFF131313});
gd.setCornerRadius(0f);

yourView .setBackgroundDrawable(gd);

GradientDrawableの詳細については。

于 2013-11-15T09:56:01.437 に答える