android - 如何在android中使用xml drawable创建半圆形填充形状?
问题描述
我想使用 xml drawble 创建一个半实心圆形?
这是我迄今为止尝试过的努力
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FCD83500"/>
<size
android:width="10dp"
android:height="5dp"/>
<corners
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp"/>
</shape>
使用上面的代码我可以创建半圆,但我不知道如何使半圆透明
我也访问过一些 SO 帖子,但找不到任何解决方案
如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。
解决方案
更新
用这个
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="90">
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="314.015"
android:viewportHeight="314.015">
<path
android:fillColor="#FCD83500"
android:pathData="M157.007,0C70.291,0 0,70.289 0,157.007c0,86.712 70.29,157.007 157.007,157.007c86.709,0 157.007,-70.295 157.007,-157.007C314.014,70.289 243.716,0 157.007,0zM31.403,157.015c0,-69.373 56.228,-125.613 125.604,-125.613V282.62C87.631,282.62 31.403,226.38 31.403,157.015z" />
</vector>
</rotate>
输出
最后我得到了使用 layer-list
来实现这个的解决方案
- A
LayerDrawable
是drawable
管理 other 数组的对象drawables
。列表中的每一个都drawable
按列表的顺序绘制——列表中的最后一个drawable
绘制在顶部。
我的代码
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="26px"
android:right="26px">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solid android:color="#00006AC5" />
<size
android:width="50dp"
android:height="50dp" />
<stroke
android:width="2dp"
android:color="#00BCD4" />
</shape>
</item>
<item
android:width="50dp"
android:height="25dp"
android:end="2dp"
android:gravity="center"
android:start="2dp"
android:top="22dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00BCD4" />
<size
android:width="10dp"
android:height="5dp" />
<corners
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp" />
</shape>
</item>
</layer-list>
输出
注意:如果您有任何其他解决方案,请随时发布答案
推荐阅读
- python-2.7 - 从保存的电子邮件中提取 Outlook 附件
- vue.js - Vue 2 将选定的数据发送回父组件
- python - 括号内的非贪婪正则表达式并包含文本
- vbscript - VBS 同步中心 同步离线文件
- python - 熊猫中的 SettingWithCopyWarning
- git - 如何更新合并分支中 Git 提交的作者?
- android - Android SharedPreference JSON 未被访问
- python - 垂直向量的 Numpy 叉积
- scala - 如何在 T 或 Future[T] 上下文中返回函数?
- python - 如何在Scala中获得不同的值作为分数图?