如何在android中使用xml drawable创建半圆填充形状?
我想使用xml drawble创建一个半填充的圆形 像这样 这是我迄今为止所做的努力如何在android中使用xml drawable创建半圆填充形状?,android,android-drawable,shapes,Android,Android Drawable,Shapes,我想使用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"/> <si
<?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"?>
<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>
用这个
<?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>
输出
注意:如果您有任何其他解决方案,请随时发布答案
我已经从矢量图形创建了代码:
<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>
在您的图像视图中
更新TextView
Drawable:
创建可绘制旋转的自定义方法
private Drawable rotate(Drawable drawable, int degree) {
Bitmap iconBitmap = ((BitmapDrawable) drawable).getBitmap();
Matrix matrix = new Matrix();
matrix.postRotate(degree);
Bitmap targetBitmap = Bitmap.createBitmap(iconBitmap, 0, 0, iconBitmap.getWidth(), iconBitmap.getHeight(), matrix, true);
return new BitmapDrawable(getResources(), targetBitmap);
}
使用方法如下:
android:rotation="90"
Drawable result = rotate(ContextCompat.getDrawable(mContext, R.drawable.ic_round), 90);
yourTextView.setCompoundDrawablesWithIntrinsicBounds(result, null, null, null);
注意:如果您想要找到SVG图像,那么您现在必须
执行上述代码。我试图找到图像,但没有找到这样的旋转
代码在这里是必需的
希望它能帮助你
谢谢。试试这个:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:color="#FCD83500"
android:width="1dp"/>
<size
android:width="20dp"
android:height="20dp"/>
<corners
android:radius="50dp"/>
</shape>
</item>
<item android:top="10dp">
<shape android:shape="rectangle">
<solid android:color="#FCD83500"/>
<size
android:width="20dp"
android:height="10dp"/>
<corners
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp"/>
</shape>
</item>
</layer-list>
使用此代码制作半圆矢量图像。如果要旋转矢量图像,请使用带有旋转元素的组标记。参考此
是否有必要使用xml drawable?否则,您也可以使用矢量图形。@BalvinderSingh可以使用矢量图形发布解决方案,谢谢,但您的代码不起作用。请检查@Goku。您在真实设备上检查过吗?警告:属性end仅用于API级别23及更高级别(当前最小值为16)
我想你会得到错误:这里不允许使用元素向量
这是个好主意,但我想在文本视图中使用它作为android:drawableEnd
所以我不能使用android:rotation=“90”
@小悟空就按上面的方法试试。嘿,谢谢你的时间,我已经找到了如何旋转向量
检查我下面的答案+1,谢谢你的帮助。谢谢你,我已经检查了你的问题,也就是说,你可以更新你的答案,谢谢你的帮助,我会接受你的答案
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="314.015"
android:viewportHeight="314.015">
<group
android:translateX="314.015"
android:rotation="90">
<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" />
</group>
</vector>