Issue
I want to create a half filled circle shape using xml drawble?
Here is my efforts that i have tried so far
<?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>
Using above code i can create half circle but i don't know how to make half circle transparent
I have also visited some SO post but unable to find any solution
- Half circle shape not work
- how to draw a half circle in android
- How to define a circle shape in an Android xml drawable file?
If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.
Solution
I have created code from Vector Graphics :
<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>
Output will be:
Now if you want to display in as per your angle:
You can use as below:
android:rotation="90"
in your ImageView
Update for TextView
Drawable:
Create custom method for rotate 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);
}
Use as below:
Drawable result = rotate(ContextCompat.getDrawable(mContext, R.drawable.ic_round), 90);
yourTextView.setCompoundDrawablesWithIntrinsicBounds(result, null, null, null);
Note: If you will find SVG image as you want then you do now have to do above code. I have tried to find image but didn't found so Rotation code is necessary here.
Hope it will help you.
Thank you.
Answered By - Pratik Butani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.