Determine Android device screen size using code

When developing Android application, we can place layout files in the res/layout for normal Android smartphone, and use a different layout files and place them in res/layout-large for large Android tablet device.In some situation, if there is a need to have different behaviors between Android smartphone device and Android tablet device, the code below can be used to determine if it is a small device or large device.

if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 
        Configuration.SCREENLAYOUT_SIZE_LARGE) {
    // logics for large screen device ...


Search within Codexpedia

Custom Search

Search the entire web

Custom Search