我可以很好地使用下面的XML
<shape android:shape="rectangle" xmlns...">
<gradient
android:startColor="#255779"
android:centerColor="#3e7492"
android:endColor="#a6c0cd"
android:angle="90"/>
<stroke android:width="1dp" android:color="#0d202e"/>
</shape>
渐变效果很好
我正在尝试使用代码做同样的事情(没有XML)
int colors [] = {0xff255779,0xff3e7492,0xffa6c0cd};
GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,colors);
setBackgroundDrawable(克);
渐变出现了,但它不同于XML中的那个,我的意思是颜色相同但梯度不一样,我认为它与xml中的开始,中间和结束颜色有关
发布于 2018-03-30 17:52:48
根据Docs
android:angle Integer。渐变的角度,以度为单位。0从左到右,90从下到上。它必须是45的倍数。默认值是0
但你正在使用GradientDrawable.Orientation。你的代码中的TOP_BOTTOM。这就是为什么梯度方向不同
你应该使用GradientDrawable.Orientation。改为BOTTOM_TOP。
https://stackoverflow.com/questions/-100007884
复制相似问题