Skip to content

A gradle script that can automatically generate different resolution dimens.xml based on small width calculation

License

Notifications You must be signed in to change notification settings

freddyfang/android-multi-resolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Multi-resolution generator

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>

How to Use

  1. Place script under your project app folder.
  2. In app level build.gradle, add following line at the very bottom.
  apply from: 'multires.gradle'
  1. Customize the script in ext section.
  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
  }
  1. Run gradle sync, after that, you will see the script generate dimens.xml from {min_swdp} to {max_swdp}, step by {res_step}.

About

A gradle script that can automatically generate different resolution dimens.xml based on small width calculation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •