Issue
i successfully created custom xml drawable file(image).i used it in my layout this is a my source code:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#1Affffff" />
<stroke
android:width="1dp"
android:color="#80ffffff" />
<corners
android:bottomLeftRadius="4dip"
android:bottomRightRadius="4dip"
android:topLeftRadius="4dip"
android:topRightRadius="4dip" />
now i want to add oval object in center position,but i don't know how to add it in center position. does enyone knoes how i can add it in center position? thanks everyone
Solution
Create an oval drawable like so
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/myColor" />
</shape>
Option 1
If you want to add an oval at the centre of that rectangle, just create another oval drawable load into a imageview and position the imageview at the centre of the imageview rendering the rectangle drawable
Option 2
First create bitmaps from the 2 drawables
Bitmap rectange = BitmapFactory.decodeResource(getResources(), R.drawable.rectangle);
Bitmap oval = BitmapFactory.decodeResource(getResources(), R.drawable.oval);
then create canvas and draw the bitmaps, play with the input of the drawBitmap
to get the positioning of your oval right.
// This bitmap will be the bitmap with oval in rectange after
// you finish drawing the canvas attached to it.
Bitmap ovalInRectangle = Bitmap.createBitmap(rectangle.getWidth, rectangle.getHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(ovalInRectangle);
canvas.drawBitmap(rectangle, 0, 0, null);
canvas.drawBitmap(oval, 0,0,null);
return ovalInRectangle;
Answered By - Bhargav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.