gpt4 book ai didi

java - 如何设置android :angle property of GradientDrawable programmatically?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:28 27 4
gpt4 key购买 nike

这是我的颜色列表:

static ArrayList<Integer> colors;
static {
colors = new ArrayList<Integer>();
colors.add(Color.parseColor("#43CFCF"));
colors.add(Color.parseColor("#1C6E9B"));
colors.add(Color.parseColor("#AC88C0"));
colors.add(Color.parseColor("#EE5640"));
colors.add(Color.parseColor("#EFBF4D"));
}

这是我的可绘制数组:

static Drawable[] drawables;
static {
drawables = new Drawable[5];
drawables[0] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(0), colors.get(1)});
drawables[1] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(1), colors.get(2)});
drawables[2] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(2), colors.get(3)});
drawables[3] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(3), colors.get(4)});
drawables[4] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(4), colors.get(0)});
}

现在,我正在遍历 drawable[],并使用 alpha 动画使第 n 个和第 (n+1) 个 drawable 交叉淡入淡出。

现在我的布局是这样的:

enter image description here

我的布局是矩形的 (GradientDrawable.Orientation : Topleft-BottomRight),但是这个方向值没有设置我的渐变线(在颜色之间)从我的矩形的右上边界到左下边界。如果我的布局是 SquareShape,它会完美地工作。

所以我想以编程方式设置每个 GradientDrawable 的角度(试错法)(不能使用 xml,因为我在代码中创建可绘制对象,否则我将不得不创建 5 个 xml,每个可绘制对象一个)。

此外,如果我的方向是 TL_BR,android:angle 的值如何工作?角度是否随引用(轴)到 TL_BR 线(0 弧度)而变化。

请帮忙!

最佳答案

尝试:

drawables[0] = new GradientDrawable(GradientDrawable.Orientation.TL_BR,  new int[]{colors.get(0), colors.get(1)});

代替:

drawables[0] = new GradientDrawable(Orientation.TL_BR,  new int[]{colors.get(0), colors.get(1)});

关于java - 如何设置android :angle property of GradientDrawable programmatically?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21674729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com