Android: Change center of linear GradientDrawable via code

前端 未结 1 1553
情话喂你
情话喂你 2020-12-21 06:22

EDIT: LOOK AT SOLUTION ABOVE

i m freaking out. all i just want to do, is setting a linear GradientDrawable, which changes the vertical center of the

相关标签:
1条回答
  • 2020-12-21 06:58

    The lacking ability to set the center programmatically for linear GradientDrawables is a registered issue already.

    But there is a workaround described here. Basically, you should create a PaintDrawable from a LinearGradient and set it as your view's background drawable. Following this solution, you can set the center in your LinearGradient constructor by mapping the colors to the positions array:

    float[] positions

    May be null. The relative positions [0..1] of each corresponding color in the colors array. If this is null, the colors are distributed evenly along the gradient line.

    (not tested, but it should do the trick for you)

    0 讨论(0)
提交回复
热议问题