Which is the best way of dealing with images in Android. Recently in Android Lollipop We had given support for SVG(Scalable Vector Graphics) concept. Which is the best way of working with images to support all resolutions PNG(placing images in particular drawable resources) or SVG(Small file sizes that compress well, Scales to any size without losing clarity (except very tiny)).
You will still need PNG images for older platforms, so the ideal workflow is to have vector-based source images that you export to PNG for various DPI buckets and convert to VectorDrawable format for API 21 devices using a project like svg2android.
Transparency. PNGs and SVGs support transparency — so they're both excellent choices for online logos and graphics. It's worth noting that PNGs are one of the best choices for a raster-based transparent file. If you're working with pixels and transparency, PNGs are a better option than SVGs.
Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.
SVG files tend to store images more efficiently than common raster formats as long as the image is not too detailed. SVG files contain enough information to display vectors at any scale, whereas bitmaps require larger files for scaled-up versions of images — more pixels use up more file space.
Lollipop (API 21) does not support SVG. It support a subset of SVG path drawing functionality through the VectorDrawable class. This class is not currently supported by appcompat, so it is only available on API 21.
You will still need PNG images for older platforms, so the ideal workflow is to have vector-based source images that you export to PNG for various DPI buckets and convert to VectorDrawable format for API 21 devices using a project like svg2android.
You can use Android Support Library 23.2 or higher. The VectorDrawableCompat class in the Support Library allows you to support VectorDrawable in Android 2.1 (API level 7) and higher.For this you need to change your build.gradle file before you run Vector Asset Studio, as described in Support Library Backward Compatibility.
//For Gradle Plugin 2.0+ android { defaultConfig { vectorDrawables.useSupportLibrary = true } } //For Gradle Plugin 1.5 or below android { defaultConfig { // Stops the Gradle plugin’s automatic rasterization of vectors generatedDensities = [] } // Flag notifies aapt to keep the attribute IDs around aaptOptions { additionalParameters "--no-version-vectors" } }
In order to support Vector Drawable and Animated Vector Drawable on devices running Android versions prior to version 5.0 (API level 21), VectorDrawableCompat and AnimatedVectorDrawableCompat are available through two new Support Libraries: support-vector-drawable and animated-vector-drawable, respectively.
Android Studio 1.4 introduced limited compatibility support for vector drawables by generating PNG files at build time. However, the vector drawable and animated vector drawable support Libraries offer both flexibility and broad compatibility — it's a support library, so you can use it with all Android platform versions back to Android 2.1 (API level 7+). To configure your app to use vector support libraries, add the vectorDrawables element to your build.gradle file in the app module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With