The Pocket Science Lab Android app has various functionalities implemented in it, one of the major implemented functionalities is the knob in the multimeter, In my previous blog I have mentioned about the knobs and how exactly it has been implemented, one the major problems in the knob is that it doesn’t fits correctly in all layouts, even though constraint layout is used , as it has different text-views positioned in a circular constraint in which exact circular radius has to be mentioned (which cannot be constrained), mentioned in my previous-blog there comes the idea of creating different layouts for different-screens in android.
Need to create multiple layouts for different screen
There arises this question of the use of creating multiple layouts for different screens when you can create a flexible layout using tools such as constraint layout. The answer to this question is that in some cases such as as the case of circular constraint or using a linear-layout one has to use use hard-coded dimensions which thus makes difference in various screens on, there comes the need of using size and orientation quantifiers i.e making layout according to screen sizes. Als
Figure 1 shows how different layouts are made for multimeter according to the screen-size.
Size quantifiers in android
Size quantifier is a name that specifies an individual configuration (in this case size) corresponding to which resources can be used.
For example, here are some default and alternative resources:
In this case -hdpi is a size quantifier, there are default size quantifiers at the drawable folder.
Making different layouts according to size-quantifiers
This blog will give a step by step guide on how to make layouts using size quantifiers.
- Right click the res folder in android studio and select New-> Android Resource directory.
- A screen like below will appear
- Change the resource type to layout.
- From the available quantifiers select the quantifier which you would require, (in our case it is size).
- After selecting the quantifier click the >> button after which the following screen will get displayed.
- Now select the screen-size and click ok to make the directory, note that only one directory can be made in a single go.
- After this make different layouts according to the screen-sizes and then save the respective alternative resources in this new directory. The resource files must be named exactly the same as the default resource files.
Thus by following these steps one can make different layouts according to screen-sizes in android.
- Support different screen sizes, Android developers https://developer.android.com/training/multiscreen/screensizes#TaskUseSizeQuali (Link to repo)
- App resources overview, Android developers https://developer.android.com/guide/topics/resources/providing-resources#ScreenSizeQualifier