![]() ![]() You can do that inside of the corners tag. Since our shape is a rectangle, we can round rectangle’s corners. Here is an example: android:shape= “oval” 2.) Rounded corners Other available shapes are oval, line and ring. If you don’t specify the shape, the default rectangle type is selected. You can specify the type of a shape using android:shape XML attribute in the shape tag. Some useful attributes that you can use when defining a shape: 1.) Shape type This is how the first example looks like: Shape root element defines that this is a ShapeDrawable. Right click on res/drawable > New > Drawable resource file > give your file a name > use shape as a root element > click Ok Create a simple gradient ShapeDrawable in XMLįirst create a new drawable resource file. Let’s start codingįirst let’s take a look at a simple example and then we will recreate a gradient as can be seen in the Spotify app/website. My opinion is that you should use Drawables ( ShapeDrawables) wherever you can, because they are easy to modify and they don’t take much space. But I think that is not a huge problem if your Drawables are simple. Another issue is that they took a bit longer to draw than a Bitmap since there is a lot of parsing and drawing going on behind the scenes. You can click here to check other Drawable types and figure out which one is right for your case. There are other subclasses as well and every one of them has its own use case. I have said before that ShapeDrawable class is a subclass of the Drawable abstract class. Of course, just like I have mentioned before we can’t use them in every case. Click for the documentation of the ShapeDrawable. Since ShapeDrawables are a subclass of the Drawable abstract class, we can use them in methods where a Drawable is expected. We can recolor and manipulate them even when the app is running and use the same ShapeDrawable multiple times in our app. That is why they can be resized and stretched as much as we want, without losing any quality. ShapeDrawables are a series of commands that tell how to draw something on the screen. Yes, sometimes that is the path we have to choose because we can’t use Drawables for every single case, but we can dramatically reduce our application’s size if we can use Drawables instead. That, of course, clutters your app with copies of the same image. When you want to use PNG or JPEG images in your application, you have to provide multiple copies of the same image for different screen densities. Then we will create some Drawables that could be used in your app and lastly for the grand finale we will try to replicate a gradient as can be seen in the Spotify app/website. Have you ever wanted to reduce your Android application’s size or make it look more interesting? If yes, then you should try out ShapeDrawables.įirst, we will go over the advantages and disadvantages of the ShapeDrawables. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |