Drawable vector resized incorrectly - android

I created a logo in Adobe Illustrator, exported it as SVG and imported it to Android Studio through Asset Studio.
When the vector is painted big, it is resized correctly (image 1), but when it's small (image 2), something goes wrong.
Both are ImageView, the second one is inside the Toolbar.
Here is the vector:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="128.0"
android:viewportWidth="128.0"
android:width="24dp" >
<path android:fillColor="#7c7c7c" android:pathData="M64,64m-64,0a64,64 0,1 1,128 0a64,64 0,1 1,-128 0"/>
<path android:fillColor="#0b5c5d" android:pathData="M63.91,63.91m-57.6,0a57.6,57.6 0,1 1,115.2 0a57.6,57.6 0,1 1,-115.2 0"/>
<path android:fillColor="#fff" android:pathData="M77.31,16.23s-25.13,0.69 -40.7,5.59c-24.64,8.76 -23.73,45.63 -6.94,56C35.88,82.05 61.59,80 61.59,80l5.32,-15.27s-17.23,5.49 -28.67,-1.47C34.3,61.12 31.87,44 40,36.94S75.16,33.3 75.16,33.3Z"/>
<path android:fillColor="#fff" android:pathData="M51.87,43c15.77,2.66 54.59,-3.2 55.95,-3.53 1.56,-0.39 -23.14,37.71 -29,51.92A73.06,73.06 0,0 0,105.28 90s-4.91,12.15 -4.88,16.64c-7.3,-1.58 -41.33,-4.25 -50.87,-3 4.3,-4.55 27.39,-38.13 31.4,-47 -12.16,0.39 -17.8,-0.47 -33.51,0.06C49.18,53.29 51.6,49.79 51.87,43Z"/>
</vector>
I have no idea what is happening.
When exporting the SVG from Adobe Illustrator I tried changing the decimal count, resizing the document to be bigger and smaller and other settings in the dialog.

Hello please check my below code i already check this with pragmatically and i got correct output.
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/black_overlay">
<ImageView
android:id="#+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
app:srcCompat="#drawable/your_drawable" />
</android.support.v7.widget.Toolbar>
If you are using other layout for toolbar then include those toolbar into those between then it's fine.
If you have still problem after this try then please put your xml code so i can check and solving your problem.

According to your drawable xml:
You have to create copy of this drawable to use in toolbar, for this toolbar you have to reduce the view port size here with toolbar height and weidth.
android:viewportHeight="YOUR TOOLBAR HEIGHT"
android:viewportWidth="YOUR TOOLBAR HEIGHT (to make it square)"

Related

How to make the vector logo smaller and fit the icon

I have made a logo ic_launcher.xml for my android application using "New Vector Asset" and copying the vector paths from the asset into the ic_launcher_background.xml
The logo that resulted is too big and cropped. In android I see only the central part, with sides, top and bottom cut off.
I would like for the vector to be smaller so it would be visible whole in the logo.
I have tried changing these values:
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
This resulted in the logo either being even bigger with more cropped out, or smaller, but not centered.
These are the paths for the vector:
<path
android:name="light_triangle"
android:fillColor="#color/colorAccent"
android:pathData="M 0,0 L 100,0 0,100 z" />
<path
android:fillColor="#color/colorPrimary"
android:pathData="M5,13.18v4L12,21l7,-3.82v-4L12,17l-7,-3.82zM12,3L1,9l11,6 9,-4.91V17h2V9L12,3z"/>
I would like for the logo to be smaller and centered. Can I somehow move the vector after making it smaller by changing height and width, or do I have to make new vector asset that is somehow smaller and centered?
UPDATE:
I have found what has to be done. I put the vectors inside a group like this:
<group android:scaleY="0.7" android:scaleX="0.7" android:pivotY="10" android:pivotX="10">
<path
android:fillColor="#color/colorPrimary"
android:pathData="M5,13.18v4L12,21l7,-3.82v-4L12,17l-7,-3.82zM12,3L1,9l11,6 9,-4.91V17h2V9L12,3z"/>
</group>
Use vector image directly in AndroidManifest.xml file
android:icon="#drawable/work_mode"
Change the android:width and android:height values without changing the android:viewportWidth and android:viewportHeight. In this way :
android:width="16dp"
android:height="16dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
I have found what has to be done. I put the vectors inside a group like this:
<group android:scaleY="0.7" android:scaleX="0.7" android:pivotY="10" android:pivotX="10">
<path
android:fillColor="#color/colorPrimary"
android:pathData="M5,13.18v4L12,21l7,-3.82v-4L12,17l-7,-3.82zM12,3L1,9l11,6 9,-4.91V17h2V9L12,3z"/>
</group>

How to fit VectorDrawable to ImageView and remove unnecessary paddings

For my Android app I've created such layer list from two vector Drawable.
The xml-code
I want to put this image into ImageView, but I have a problem with paddings which I can't remove (marked in red).
To solve this issue I've already applied follow steps:
Explicitly set paddings to 0 value
Set "AdjustViewBound" to true
Played with "fitType" attributes.
None of this hadn't been worked for me. Please help me to resolve this problem.
You should get a whole drawable with the circle and person in one vector. But if you really need these two files to be separated, you must change the path in the XML code.
Accordingly to this
https://stackoverflow.com/a/50114171/3368784 you can resize your path by rewriting your primary_dark_color_circle.xml
as:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<group
android:pivotX="12"
android:pivotY="12"
android:scaleX="1.2"
android:scaleY="1.2">
<path
android:fillColor="#0088CC"
android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0" />
</group>
</vector>

Android - Background color with different color and angles

I'm trying to figure out how to create this background in xml,
couldn't find anything that helped me.
Ignore the circle image of the kid and the text of course, I am talking about the background itself, is there a way to create something like that in xml?
Thanks in advance for any help.
cheers!
I'm guessing you moved on, but you can do this using Vector Drawables.
The following is not accurate (the line is not completely straight), but should give you a good start:
New XML file:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp"
android:width="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<path
android:name="dark_triangle"
android:fillColor="#color/blue"
android:pathData="M 0,100 L 0,80 60,70 100,80 100,100 z" />
<path
android:name="light_triangle"
android:fillColor="#color/color_light_blue"
android:pathData="M 60,70 L 100,65 100,80 z" />
</vector>
In your layout:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
app:srcCompat="#drawable/test"
/>
You might need to add this to your layout as well:
xmlns:app="http://schemas.android.com/apk/res-auto"
Notes:
Some more resources if someone will be interested: 1 2.
There's a preview for Vector Drawables in Android Studio.
Vector Drawables has been introduced in API 21, but should be supported in older APIs.

Android: Vector has blur on android 4.4

There TextView and I want him to do VectorDrawable background. I do vector.xml
<vector android:height="24dp" android:viewportHeight="114.0"
android:viewportWidth="494.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF"
android:pathData="M12,86.61L2.19,76.51L12,67.18L12,8C12,3.58 15.59,0 20.01,0L483.99,0C488.42,0 492,3.58 492,8L492,102C492,106.42 488.41,110 483.99,110L20.01,110C15.58,110 12,106.42 12,102L12,86.61Z"
android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>
and this VectorDrawable on android 4.4 has a fuzzy edge (not clear), but on android 5.0+ everything looks good (as needed).
Help solve the problem with android 4.4
Use this when using ImageView
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_add" /> <- This may help
Vector Drawables are also supported in cases like TextView's drawableLeft property
(with custom Textview to handle vector for PreLollipop version).

Android Vector Asset Studio gives extra padding to some vector images

I'm trying to import some icons from Material Vector package in Vector Asset Studio.
But they come with padding.
Why does this happen and how can I remove it?
This is inconvenient because this means if I want my icon to be 17dp x 17dp in XML, then I need to set it more than 17x17 to make up for the padding.
Android Vector Asset
You are able to scale a vector that will remove additional space. This is possible using group tag. Just modify your vector xml file.
From
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z" />
</vector>
to
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<group
android:pivotX="12"
android:pivotY="12"
android:scaleX="1.5"
android:scaleY="1.5">
<path
android:fillColor="#FF000000"
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z" />
</group>
</vector>
As result
You can adjust for any "implicit" padding that may be contained within a VectorDrawables source image (.SVG, .PSD) by setting your ImageViews android:scaleType to the appropriate value so it can handle the padding that is secretly contained in the VectorDrawables source image. You will also need to set android:adjustViewBounds="true".
For example, lets say your VectorDrawable has some really annoying padding at the start of the image when you display it. You have no idea why it's there because you aren't setting any android:paddingStart on the ImageView... what you need to do is set the ImageViews android:scaleType to fitStart and android:adjustViewBounds to true.
tl;dr
Adjust your ImageViews android:scaleType to handle any "implicit" padding that is contained in your VectorDrawables source file (.SVG, .PSD). Also set android:adjustViewBounds="true".
Quick Example:
<ImageView android:id="#+id/vectorDrawable_imageView"
<!--Other ImageView settings-->
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="#drawable/vector_with_implicit_padding_at_start"
/>
This will remove that annoying "implicit" padding that was at the start of your VectorDrawable.
Note: Adjust the android:scaleType according to your rendering needs.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="28"
android:viewportHeight="28">
<group
android:translateX="2"
android:translateY="2">
<path
android:fillColor="#8A333333"
android:pathData="M13.12,2.06L7.58,7.6c-0.37,0.37 -0.58,0.88 -0.58,1.41V19c0,1.1 0.9,2 2,2h9c0.8,0 1.52,-0.48 1.84,-1.21l3.26,-7.61C23.94,10.2 22.49,8 20.34,8h-5.65l0.95,-4.58c0.1,-0.5 -0.05,-1.01 -0.41,-1.37 -0.59,-0.58 -1.53,-0.58 -2.11,0.01zM3,21c1.1,0 2,-0.9 2,-2v-8c0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2v8c0,1.1 0.9,2 2,2z" />
</group>
</vector>
android:viewportWidth += android:translateX * 2 (padding start / end)
android:viewportHeight += android:translateY * 2 (padding top / bottom)
This padding is on some icons so that all of the icons can align properly. For example, if in that dialog, you pick ic_3d_rotation_24dp, you'll see the icon goes all the way to the edge of the bounds.
PS if you aim to have all your sizes be a multiple of 8dp, things will line up nicely and look great.

Categories

Resources