我已经设置了我的LinearGradient
TextPaint paintText = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paintText.setColor(Color.WHITE);
paintText.setTextSize(size);
paintText.setStyle(Paint.Style.FILL_AND_STROKE);
paintText.setShadowLayer(3f, 3f, 3f, Color.BLACK);
int pL = bitmap.getWidth() / 100;
int pT = bitmap.getHeight() / 100;
StaticLayout mTextLayout = new StaticLayout(
gagTitle,
paintText,
newCanvas.getWidth(),
Layout.Alignment.ALIGN_NORMAL,
1.0f,
0.0f,
false);
int dummyHeight = mTextLayout.getHeight();
Shader shader = new LinearGradient(0, 0, 0, (dummyHeight * 2), Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR);
Paint paint = new Paint();
paint.setShader(shader);
newCanvas.drawRect(new RectF(0, 0, bitmap.getWidth(), dummyHeight), paint);
我不知道为什么,但在生成的渐变结束时,除了透明之外,它的黑色不那么明亮。
结果如下
最好的问候
答案 0 :(得分:1)
LinearGradient坐标不是相对的,它们以画布网格的绝对值给出。
在你的情况下也没有必要有镜像边界。
Shader shader = new LinearGradient(0, 0, 0, dummyHeight, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);