I can use the following XML just fine
<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>
the gradient come up nicely
i am trying to do the same thing just using code (no XMLs)
开发者_高级运维int colors[] = { 0xff255779 , 0xff3e7492, 0xffa6c0cd }; GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors); setBackgroundDrawable(g);
The gradient DOES come up but its not the same as the one the one from XML, i mean the colors are same but gradient is not same, i think it has to do with the start,middle,end colors in the xml
also how do i add a stroke
any help will be greatly appreciated
According to Docs
android:angle
Integer. The angle for the gradient, in degrees. 0 is left to right, 90 is bottom to top. It must be a multiple of 45. Default is 0
but you are using GradientDrawable.Orientation.TOP_BOTTOM in your code. That's why gradient directions are different
You should use GradientDrawable.Orientation.BOTTOM_TOP instead.
精彩评论