We should use dp/sp in android development cause it will be auto-scaled depends on devices' screen resolution. However, it's not always looks so good. Suppose we have a design that is based on a device with 250dp width, and there is a 25dp width button on it. Everything looks great until we run our app on a bigger device with 500dp width. Now our button looks 1/2 smaller than we expected.
This script can automactially generate other dimens for you. For example, we now will have two dimens.xml, one is defined by youself:
dimens.xml
<dimen name="btn_width">25dp</dimen>
and another one will be generated by the script:
dimens.xml(sw500dp)
<dimen name="btn_width">50dp</dimen>
- Place script under your project
appfolder. - In app level
build.gradle, add following line at the very bottom.
apply from: 'multires.gradle'
- Customize the script in
extsection.
ext {
base_swdp = 250 // 250dp by default
min_swdp = 250 // 250dp by default
max_swdp = 1000 // 1000dp by default
res_step = 10 // 10dp by default
}
- Run gradle sync, after that, you will see the script generate dimens.xml from {min_swdp} to {max_swdp}, step by {res_step}.