相关疑难解决方法(0)

试图绘制一个按钮:如何设置笔触颜色以及如何在不知道高度的情况下将渐变"对齐"到底部?

我正在以编程方式创建一个按钮.它是圆形的,有渐变背景,工作正常,看起来不错,但我不能做我想要的两件事:

  1. 使用给定颜色设置1像素笔划.我尝试了getPaint().setStroke(),但无法弄清楚如何设置笔触颜色.我该怎么办?
  2. 将渐变与按钮底部对齐,无论其高度如何.这可能吗?

作为参考,这是我正在使用的代码:

Button btn = new Button(context);
btn.setPadding(7, 3, 7, 5);
btn.setTextColor(text_color);

// Create a gradient for the button. Height is hardcoded to 30 (I don't know the height beforehand). 
// I wish I could set the gradient aligned to the bottom of the button.
final Shader shader = new LinearGradient(0, 0, 0, 30,
    new int[] { color_1, color_2 },
    null, Shader.TileMode.MIRROR);

float[] roundedCorner = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }
ShapeDrawable …
Run Code Online (Sandbox Code Playgroud)

android

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1