如何给梯度的TextView android系统中? [英] How to give gradient to TextView in android?
问题描述
我从一段时间才TextView的给予梯度android.but没有得到妥善的解决办法在任何地方进行搜索。
i search from while for giving gradient to textView in android.but not getting proper solution any where.
我有一个这样的屏幕
i have the screen like this
如果我把图像,文字,但我有梯度许多TextView的,那么应用程序可能是规模大。 因此,如果有人知道的解决方案,请张贴。 谢谢你。
if i put the images as text, but i have many textview which having gradient,then application may be large in size. so if anybody know the solution please post it. Thanks.
推荐答案
在这里不言而喻,
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode = TileMode.REPEAT;
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 35,color,position, tile_mode);
Shader shader_gradient = lin_grad;
your_text_view.getPaint().setShader(shader_gradient);
编辑:
嗨@android开发,
Hi @android developer,
如果你想要做一些垂直或任何渐变到视图,
If you want to do some vertical or any gradients to the view,
请使用,
的RadialGradient
而不是的LinearGradient。
唯一的事情就是你要调整,
Only thing is you have to adjust,
x coordinate of the center of the radius.
y coordinate of the center of the radius.
and also,
radius value of the view.
和使用平铺模式为镜,而不是重复。
and use Tile Mode as Mirror instead of Repeat.
我有样,但它可能并不确切你想要什么,
I have sample but it may not exact of what you want,
TileMode tile_mode = TileMode.MIRROR or TileMode.REPEAT;
RadialGradient rad_grad = new RadialGradient(0, 3, 5, Color.BLUE,Color.RED,tile_mode, tile_mode);
Shader shader_gradient = rad_grad;
your_text_view.getPaint().setShader(shader_gradient);
和您可以使用 SweepGradient
而不是的LinearGradient
也。
And you can use SweepGradient
also instead of LinearGradient
.
这篇关于如何给梯度的TextView android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!