ic_launcher_foreground not fitting - android

I'm trying to make my new app compatible with the latest Android requirements, which means including an SVG version of my app icon. I was successful at converting my PNG icon to SVG, and I was able to include the resulting path in the ic_launcher_foreground.xml, but when previewing the result in the ic_launcher.xml or ic_launcher_round.xml the SVG is either too big, or not in the right position.
Normally one would apply scaling or transformation to fix that. Inkscape does this, and leaves the actual path values alone. But the android file format does not seem to support scaling or transforming.
How do I make an SVG path fit the 108x108 (or better 72x72 center) as required by Android? It should be possible to use any freely available SVG icon and make it fit, right?

Related

Delete padding or Force fitting or Delete empty space from square Vector asset to Fit a Rectangular button?

I'm trying to adjust the all_inclusive svg image to my rectangular button. The shape itself is rectangular as well but the vector asset is square (24x24) with white spaces above and under the shape. These spaces force the shape itself to be very small. How to make the all inclusive svg rectangular by deleting that padding on top and on bottom?
In this picture the image is set to fit the guidelines on the left, top and right side:
<ImageView
android:id="#+id/imgInfinity"
app:srcCompat="#drawable/ic_infinity"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="0.75"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="0.75"
app:layout_constraintEnd_toEndOf="0.25" />
Things that did not work:
pivot vector asset with a group -> I just cant figure out the dimensions without messing up the original shape. Same storty with scaleX/Y or translateX/Y. I got it to work on my other buttons with simpler shapes though.
adjusting android:viewportheight or android:height -> it deshapes the picture to a weird form
crop svg online --> as Googles original SVG pathData is already 580 characters long, cropping tools only make it to large for android to deal with (above 1000 charactes)
crop svg picture with word and extract from zip file-> it doesnt compress svg images so it stays rectangular with the white spaces above and under.
Set a seperate horizontal guideline for the top of the picture. It does the trick but one or multiple guidelines for each image gets very messy. There must be a better way, right?..
ACCEPTED SOLUTION (edit with InkShape):
Install InkShape
Open SVG
Click on picture once to select it
Go to File-> Document Properties and click 'Resize pager to drawing or selection' (this button is hidden on the first tab, click +Resize page to content to show the option);
Save
extract pathData and (viewport)width/heights from saved file.
The viewportHeight attribute defines the size of the "canvas" that the path is drawn on (i.e., it defines what the coordinates in the path data actually "mean").
The height attribute defines the intrinsic size of the drawable.
The original vector has 6.5 units (in the viewport) of white space at the top and the bottom. That means that you can look for any pathData command that uses a capital letter, and subtract 6.5 from the y coordinate. That leaves you with this:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="13dp"
android:viewportWidth="24.0"
android:viewportHeight="13.0">
<path
android:fillColor="#FF000000"
android:pathData="M18.6,0.12c-1.44,0 -2.8,0.56 -3.77,1.53L12,4.16 10.48,5.5h0.01L7.8,7.89c-0.64,0.64 -1.49,0.99 -2.4,0.99 -1.87,0 -3.39,-1.51 -3.39,-3.38S3.53,2.12 5.4,2.12c0.91,0 1.76,0.35 2.44,1.03l1.13,1 1.51,-1.34L9.22,1.7C8.2,0.68 6.84,0.12 5.4,0.12 2.42,0.12 0,2.54 0,5.5s2.42,5.38 5.4,5.38c1.44,0 2.8,-0.56 3.77,-1.53l2.83,-2.5 0.01,0.01L13.52,5.5h-0.01l2.69,-2.39c0.64,-0.64 1.49,-0.99 2.4,-0.99 1.87,0 3.39,1.51 3.39,3.38s-1.52,3.38 -3.39,3.38c-0.9,0 -1.76,-0.35 -2.44,-1.03l-1.14,-1.01 -1.51,1.34 1.27,1.12c1.02,1.01 2.37,1.57 3.82,1.57 2.98,0 5.4,-2.41 5.4,-5.38s-2.42,-5.37 -5.4,-5.37z"/>
</vector>
Then, once the whole shape has been moved "up" by 6.5 units, you can subtract 11 (6.5 * 2) from both the viewport and the intrinsic height.
The end result is a 24x13dp shape, which should scale much better in wide views.
Update using Inkscape version 1.1:
Unfortunately, the latest version of Inkscape (1.1) no longer will import a vector drawable file directly, so the original answer is not 100% correct. That answer will probably work with other editors that can handle vector drawable files.
Here is an update to that answer that works with later versions of Inkscape to remove all padding from a vector drawable.
Convert vector drawable to scaled vector graphic (SVG):
Open Alex Lockwood's Shape Shifter site
Drag the vector drawable file from Android Studio to Shape Shifter.
Export the image as an SVG to a local file
Now that we have an SVG file, we can edit it with Inkscape:
Install Inkscape if not already installed.
Open SVG file in Inkscape.
Click on the image to select it.
Resize the image to the selection (Shift+Ctrl+R or Edit->Resize Page to Selection). You can also specify an alternate size if you desire some padding.
Save the image as an SVG file.
The image is now cropped in an SVG file. We need to convert it back to a vector drawable.
In Android Studio import the SVG file as a vector drawable. (File->New->Vector Asset) Asset Type = "Local file (SVG, PSD).
Once imported, the vector drawable no longer has any padding.
Use an image editor that can handle SVG files to crop the image. I used InkScape but there are others. Once the image is cropped, you can import it into Android Studio as an XML file.
Here's the new update on this topic:
https://code.google.com/p/android/issues/detail?id=202019
It looks like using android:scaleType="fitXY" will make it scale correctly on Lollipop.
From a Google engineer:
Hi, Let me know if scaleType='fitXY' can be a workaround for you , in
order to get the image look sharp.
The marshmallow Vs Lollipop is due to a special scaling treatment
added into marshmallow.
Also, for your comments: " Correct behavior: The vector drawable
should scale without quality loss. So if we want to use the same asset
in 3 different sizes in our application, we don't have to duplicate
vector_drawable.xml 3 times with different hardcoded sizes. "
Even though I totally agree this should be the case, in reality, the
Android platform has performance concern such that we have not reach
the ideal world yet. So it is actually recommended to use 3 different
vector_drawable.xml for better performance if you are sure you want to
draw 3 different size on the screen at the same time.
The technical detail is basically we are using a bitmap under the hook
to cache the complex path rendering, such that we can get the best
redrawing performance, on a par with redrawing a bitmap drawable.

Android Studio 3.2 Add Image Of Custom Size (not icon)

When I right-click the Drawable folder and click New -> Image Asset, I'm presented with only four options: action and tab bar icons, launcher icons, launcher icons (legacy), and notification icons.
What if I want to add an image to just use in my app (not as a tiny icon)? Selecting any of the options above causes Android Studio to scale the image down to like 24x24dp when I want to display it at 100x100dp. So, when I display it, it looks really blurry. Why isn't there an option to add an image asset that's not tiny?
Limited modification is to comply with the material design specification. you could use vector asset if you want to get different size image.
and notice you should down image with SVG format, read the ref in here
another way is using thrid party plugins like Android Drawable Importer, which is flexiable and simpler.
Just copy the image to your drawable folder in the Android sidebar view. Make sure it goes into drawable and not one of the density-dependent folders, and you'll have an image with a custom size.
Be aware that images can't be too big in Android. It shouldn't be larger than 1600px in either dimension, otherwise you run the risk of a laggy interface or an OutOfMemory error.

Which kind of images is appropriate for VectorDrawable?

VectorDrawable is a new feature for Android after API Level 21, Which add support for vectorgraph. But I have a question for VectorDrawable, is it suitable for me to replace most of images in my project to VectorDrawable. In the android offical dev site I saw a few words :
A vector drawable is appropriate for simple icons. The material icons provide good examples of the types of images that work well as vector drawables in an app. In contrast, many app launch icons do have many details, so they work better as raster images.
Is that means VectorDrawable is only appropriate for simple icons like offical material icons, images have many details aren't appropriate to use VectorDrawable.
Sorry for my poor english skills, hope you guys can understand me! 😬
I plan to use VectorDrawable for all my project image resource if it is ok.
You're basically right.
Vector images describe shapes and geometry, and need to be rendered into bitmaps (a grid of pixels). This requires some math, calculating the pixels that represent the lines and curves defined by the icon.
The more complicated an icon gets, means the more shapes that are required, and the more calculations that need to be done.
On the other side, if you already have the icon rendered to a specific scale, like with png images, all of the pixel values have already been calculated. Now it just needs to be converted to a bitmap and scaled to the size it gets displayed at.
So depending on the situation, an icon may be able to decode and scale from a png file faster than rendering from a vector drawable, or vice versa, it all depends on the icon.
It's hard to say exactly how simple an icon needs to be, so try it out and make sure it runs well on a range of devices.

How to export menu icons in high quality using Illustrator

I made simple menu icons which look the way I want them to look when in Illustrator, but when I place them in my app they look pixelated and bad.
Here is it in my app (as you can see, the text is not pixelated):
This is how it looks in Illustrator (I cut the icons and pasted them next to the other two, that's why the background is in different color):
I made the icons on 72x72 px canvas and exported them as .png file.
I am using Android Studio to make my app, and use simple
android:background="#drawable/back_button" to set the image/icon for the ImageButton.
I never try Illustrator to put icons, but I am directly download icons from flaticon that provides any type of file and size too
Two way to get different canvas file in android studio.
Android Studio-> File-> Image Asset or Vector Asset
upload your file and set as you need
Icon Generator
From this you can get directly res folder with different canvas image.
Mostly I prefere first.
Thanks
these icons as shown in fig. have a background color assigned by you in illustrator, no matter these are exported as png format or jpg!
First go back to illustrator and try to make background of images transparent as you assigned greyish color, tell me if it works. That's great you are making icons for yourself. Good work.
I think when you save the file please try to save it (SVG) format & then place it.

Using vector images to scale for app platforms

Images in apps come in many shapes or sizes, but to save space and editing time is there a way to use scaleable vector images?
Ideally I would have one vector image at middle resolution, I could then detect the screen size and scale the vector how I need and add the background using some custom gradients.
I'm using titanium for this.
Titanium doesn't yet support vector graphics, though it is available in native Android code via Shape Drawables. There is a third-party SVG library available for Android SDK.
For Titanium, branch the code based on the device screen size (Titanium.Platform.DisplayCaps), and find an image that works with decent performance on the device.
You can use PNGs with transparency and apply a background color to your view object.
I've found away round making different sized drawable:
Basically just one have folder called drawable within the res folder.
Make your artwork in what ever you use but make it large (at least 1080p for future devices).
Save the image's as PNG within the drawable folder but save them large. (IE at least 1000x1000)
Write a function that loads in the PNG but scales it (according to screen size & percentage of what size you want the drawable to be. So 20% of 800px width is 120px). I've managed to do this bit with 30ish lines of code, can't paste my code since I'm not on my working machine.
For me this has worked across all my apps for all devices, I've not had a single crash yet (1000's of installs, including Live Wallpapers).

Categories

Resources