![]() VectorDrawables aren't any smaller than the WebP format. Then I'll go back to my layout file and I'll change the file that I'm looking at from monster01 to ic_monster01 I look at that in Design view and see that Android Studio recognizes the format and then I'll run the application on my device to make sure that everything still works as it did before. ![]() To make sure that that file's been registered, I'll select Build, Make Project. And that creates the new file that's now called ic_monster01.xml. Alternatively, I can click the Override checkbox and then the image will look the same as it did before. In an image like this, that originally wasn't square, that would distort the image. I can set the size to a square aspect ratio. And I'll go the app module and right click and then choose New, Vector Asset. But again I wouldn't be able to use this file directly. ![]() And Android Studio successfully previews it. Now in my project scope, I'll show that I've included these SVG files. You have to convert those files using a tool in Android Studio called the Android Asset Studio. This is similar to traditional SVG files that work on the web. Now if you like, you can also use an XML format, known as a VectorDrawable. My image appears and it's exactly the same format as the original PNG file. I'll run the application to make sure that the application looks and behaves the same. Because remember that the resource ID only references the beginning of the file name and not the file extension. Back in my layout file, I don't have to make any changes. And it looks exactly the same as the original. I'll click Finish and there's my new WebP file. Notice that the resulting image will be much smaller than the original and you can adjust the quality to get the results you want. And you'll see a preview of how your image will be converted. Make sure that you've deselected the option to skip images with transparency, because this image does have transparency. I'll right click on my PNG file in my resources directory and then down at the bottom of the menu, I'll choose Convert to WebP. It's very easy to convert your existing PNG and JPG files. ![]() And if your application has a minimum SDK of API level 18 or later, that's Android 4.3, then you can also support transparency. The WebP format is also a bitmap format, but it's compressed smaller than PNG files. But there are some more contemporary formats that it also supports that you might want to use. Android supports traditional web-based image formats such as JPG or PNG. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |