Coder Social home page Coder Social logo

yuludimension's Introduction

YuluDimension

Android Native Dimensions for all mobile devices

Installation

Add the Following to your gradle file.

Add it in your root build.gradle at the end of repositories:

         allprojects {
            repositories {
              ...
              maven { url 'https://jitpack.io' }
            }
         }

Add the dependency

          implementation 'com.github.saurabhYulu:YuluDimension:1.0.0'

Android introduced the “Smallest Width (SW)” qualifier in Android 3.2.

The Smallest-width qualifier allows to target screens that have a certain minimum width given in dp.

Lets take three layout folders named res/layout, res/layout-sw600dp and res/layout-sw720dp. We also have some layouts named main.xml, details.xml and item.xml in base layout folder. We override details.xml, item.xml in res/layout-sw600dp folder and item.xml in res/layout-sw720dp folder.

                  res/layout
                     main.xml
                     details.xml
                     item.xml

                  res/layout-sw600dp       // 7.0”  tablet 1024x600 mdpi
                     details.xml
                     item.xml
                  res/layout-sw720dp       // 10.1” tablet 1280x800 mdpi
                     item.xml
                     

On a device with dimensions 640 x 360 dp.

Between 640 and 360 the smallest width is 360 dp. Now the device will compare this smallest width with the folder name. As 360dp is less than 600dp and less than 720dp. So all the layout will come from res/layout folder. All the layout will come from res/layout folder.

On a device with dimensions 1024 x 600 dp.

Here, Between 1024dp and 600dp the smaller one is 600dp. Now compare this value agains the folder name. 600dp is equal to the 2nd folder res/layout-sw600dp. So details.xml and item.xml will come from this folder. But notice that main.xml is not declared in this folder. So it fall back to a less specific folder which is base folder. So main.xml will come from res/layout folder.

details.xml and item.xml will come from res/layout-sw600dp main.xml will come from res/layout folder.

On a device with dimensions 1280 x 800 dp.

Here between 1280 and 800 dp the smaller one is 800 dp. If you compare this value you will see it satisfies all the folders. However, the device will choose most specific folder first which is res/layout-sw720dp. So item.xml will come from res/layout-sw720dp folder. But details.xml and main.xml is defined in this folder. So now the device will fall back to less specific folder which is res/layout-sw600dp. So detail.xml will come from this folder. But main.xml is not also defined here. So main.xml will come from base layout folder. item.xml will come from res/layout-sw720dp detail.xml will come from res/layout-sw600dp. main.xml will come from res/layout folder.

yuludimension's People

Contributors

saurabhyulu avatar

Watchers

 avatar

Forkers

lathkarmayur

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.