如何在可绘制的中风中设置梯度
我正在尝试创建一个可以用破折号绘制的圆圈。我能够用仪表板实现圆圈,但无法应用梯度颜色。有什么办法吗?提前致谢。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="@dimen/size60"
android:height="@dimen/size60" />
<stroke
android:width="1dp"
android:color="@color/white"
android:dashWidth="3dp"
android:dashGap="1dp" />
</shape>
查看已达到的视图:
所需的视图:
I am trying to create a circle drawable with a dash. I am able to achieve circle with dash but am not able to apply gradient color. Is there any way to do it? thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="@dimen/size60"
android:height="@dimen/size60" />
<stroke
android:width="1dp"
android:color="@color/white"
android:dashWidth="3dp"
android:dashGap="1dp" />
</shape>
View achieved:
View Required:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只有仅使用XML AFAIK创建梯度环的方法。使用自定义绘制,您会有更好的运气。以下将扫描渐变着色器与 paint 对象组合在一起,以创建一个从头到尾具有梯度的环。
对于API 24及更高版本,您可以将其绘制到XML文件中,并像其他XML绘制一样使用它。
对于API 24之前的API,您需要以编程方式使用此自定义绘制。
There is not a way to create a gradient ring using just XML AFAIK. You'll have better luck using a custom drawable. The following combine a sweep gradient shader with a Paint object to create a ring that has a gradient from start to end.
For API 24 and higher, you can place this drawable into an XML file and use it like any other XML drawable.
For APIs before API 24, you will need to work with this custom drawable programmatically.