Xdimen - Support multiple screen sizes easily by scaling your dimensions

Overview

Xdimen

Plugin Portal Android Arsenal

Support multiple screen sizes easily by scaling your dimensions.

How does Xdimen work?

When you have a UI design with a specific dimension, and you need to support different mobiles or tablets in portrait or landscape. This case Xdimen can help you to generate scalable dimesions for common devices' screen sizes.

Xdimen generates an alternative res directory for every common screen width (configurable) and scales your design dimensions.

Xml resources are generated with help of kotlin xml builder

Find more about Xdimen here

Usage

Plugin Portal

Add to project

Xdimen must be applied in an android project.

Groovy
  plugins {
    id 'io.github.islamkhsh.xdimen' version "$latest_version"   
    // agp plugin
  } 
Kotlin
  plugins {                         
    id("io.github.islamkhsh.xdimen") version "$latest_version"  
    // agp plugin
  }

Configure Xdimen

All properties are optional, only designWidth is required. Properties are discussed in more detail in below section.

Groovy
  xdimen {
    deleteOldXdimen = true
    designWidth = 411 // required
    designDpi = mdpi()
    targetDevicesWidth = [360, 375, 411]
    dimensRange {
        minDimen = -10
        maxDimen = 600
        step = 0.5d
    }
    fontsRange {
        minDimen = 10
        maxDimen = 60
        step = 1.0d
    }
}
Kotlin
  xdimen {
    deleteOldXdimen.set(true)
    designWidth.set(411) // required
    designDpi.set(mdpi())
    targetDevicesWidth.set(phonePortrait)
    dimensRange {
        minDimen.set(-10)
        maxDimen.set(500)
        step.set(0.5)
    }
    fontsRange {
        minDimen.set(10)
        maxDimen.set(60)
        step.set(1.0)
    }
}

Use scaled dimens

After generate xdimen resources (see next section) you can use the dimens

">
   <TextView android:layout_width="@dimen/x100dp"    # width in design is 100dp
             android:layout_height="@dimen/x50_5dp"  # height in design is 50.5dp
             android:padding="@dimen/neg_x6_5dp"     # padding in design is -6.5dp
             android:textSize="@dimen/x12sp"         # textSize in design is 12sp
             />

Tasks

To execute a task, make sure you execute it on an android project using one of these ways

  • $ gradle :prjectName:taskName.
  • From gradle tool window under android group.
  • From Run AnyThing window.

generateXdimen

Generates alternative resources for every device width in targetDevicesWidth set and for every created resource qualifier it scales the dimensions to fit with this width. It uses configured properties to calculate a scaling factor, get the range of dimensions to generate and the list of screen widths' to target.

deleteXdimen

Delete the previous generated xdimen resources unless you renamed the res file or dir. It will be executed before generateXdimen if you set deleteOldXdimen property by true.

Configuration properties

deleteOldXdimen

By setting it when you execute generateXdimen task deleteXdimen will be executed first to delete all previous generated xdimen resources and their dirs if the directory contains only xdimen.xml file.

If you renamed the xdimen.xml file or its directory for any reason, this file won't be deleted.

Default value: true.

designWidth

The value of screen width of your design in dp unit. It will be used with designDpi to calculate the relativeDesignWidth (width relative to main density mdpi) and then calculate a scaling factor for every screen width in targetDevicesWidth.

If your design is in px set its width in this property and set designDpi to be mdpi as in mdpi 1px = 1dp.

No default value because it's required and must be configured.

designDpi

The design screen density (dot per inch) see more. This will be used with designWidth to calculate the relativeDesignWidth.

Default value is: mdpi

Predefined densities: for every density in common densities there's a method with its name ( ldpi(), mdpi(), hdpi(), ... etc), Also there's a method to set custom density dpi(value).

targetDevicesWidth

The width of screens of devices which you target. For every width in this list, an alternative resource will be generated with scaled dimensions.

ex: if the list is [350, 400] then

...
-> values/xdimen.xml            # Devices with screen-width less than 350dp.
-> values-w350dp/xdimen.xml     # 350dp <= screen-width < 400dp
-> values-w400dp/xdimen.xml     # screen-width >= 400dp
...

You can use a predefined set as it's, adds or removes from it, or provide your own set.

Default value is: [designWidth] set of designWidth provided value.

Predefined sets for common devices:

  • phonePortrait: common phones in portrait orientation.
  • phoneLandscape: common phones in landscape orientation.
  • tabletPortrait: common tablets in portrait orientation.
  • tabletLandscape: common tablets in landscape orientation.

  • devicesInPortrait: common phones and tablets in portrait.
  • devicesInLandscape: common phones and tablets in landscape.

You can combine multiple devices list, but I recommend not to target both portrait and landscape unless you provide a custom layout for landscape or using Pane Layout.

These lists were collected from many sources: Wikipedia, ScreenSize, Pixensity and others.

dimensRange

The range of dimensions you want to be generated and scaled.

  • minDimen: the minimum dimen to be generated.
  • maxDimen: the maximum dimen to be generated.
  • step: the step between two generated dimen.

Default value: minDimen=-10, maxDimen=600, step=1.00.

fontsRange

The same of dimensRange but for fonts dimensions range.

Default value: minDimen=6, maxDimen=48, step=1.00.

Screenshots

screenshots

You might also like...
Android Library for making animated tutorials inside your app
Android Library for making animated tutorials inside your app

##SlidingTutorial Cleveroad introduces Sliding Tutorial Library for Android Hey guys, hope you haven’t started developing a tutorial for your Android

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included 🚀 • Setup 🛠️ • Migration Guide 🧬

A flexible, easy to use, unique drawer library for your Android project.
A flexible, easy to use, unique drawer library for your Android project.

Duo Navigation Drawer This Android library provides an easy way to create an alternative navigation drawer for android. Instead of a drawer that slide

Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way.

Alligator Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way. Features Any app

Dismiss your keyboard by tapping anywhere outside it.
Dismiss your keyboard by tapping anywhere outside it.

Keyboard Dismisser What is this? Keyboard Dismisser is a simple library that allows you to dismiss keyboard by tapping anywhere outside it. Currently

Navigation Component: THE BEST WAY to create navigation flows for your app
Navigation Component: THE BEST WAY to create navigation flows for your app

LIVE #017 - Navigation Component: A MELHOR FORMA de criar fluxos de navegação para o seu app! Código fonte do projeto criado na live #017, ensinando c

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.

An Android staggered grid view which supports multiple columns with rows of varying sizes.

AndroidStaggeredGrid ##Notice - Deprecated - 09-2015 This library has been deprecated. We will no longer be shipping any updates or approving communit

Learn how to create a layout that works with all screen sizes of the device.

Learn how to create a layout that works with all screen sizes of the device.

A library to quickly and easily enable multiple monitoring & support platforms for your mobile apps

You have a small team. Setting up crash reporting tools, event tracking tools, and log management services is not what you want to spend your hours do

Charts/graphs library for Android compatible with API 8+, several chart types with support for scaling, scrolling and animations
Charts/graphs library for Android compatible with API 8+, several chart types with support for scaling, scrolling and animations

HelloCharts for Android Charting library for Android compatible with API 8+(Android 2.2). Works best when hardware acceleration is available, so API 1

Androidicons is a professional, handcrafted icon set with 250 icons in 14 different colors and 5 sizes, including an icon font and all sources.

Android Developer Icons Android Developer Icons is a custom icon set, created by Opoloo. Included are: 250 hand-crafted, pixel-perfect icons in 5 size

Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo.

CutoutScreenSupport Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo. Usage whether the mobile phone is cutout

 🌏 Android/IDEA localization plugin. supports multiple languages and multiple translators.
🌏 Android/IDEA localization plugin. supports multiple languages and multiple translators.

English | 简体中文 AndroidLocalizePlugin 🌏 Android/IDEA localization plugin. supports multiple languages and multiple translators. Features Multiple tran

 A MaterialChipSetWidget is used to hold multiple chipsets 🤩 and each chipset has multiple values. 🔖
A MaterialChipSetWidget is used to hold multiple chipsets 🤩 and each chipset has multiple values. 🔖

A MaterialChipSetWidget is used to hold multiple chipsets 🤩 and each chipset has multiple values. 🔖

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.

⚡ A powerful & easy to use chart library for Android ⚡ Charts is the iOS version of this library Table of Contents Quick Start Gradle Maven Documentat

NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect.
NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect.

NTabLayout Brief NTabLayout is a simple tab bar custom view under android which has click-sliding and scaling up animation effect. This tab bar's effe

This application is used to adjust the scaling of kubernetes deployments depending on the message-count of given RabbitMQ queues.

PodAutoScaler This application is used to adjust the scaling of kubernetes deployments depending on the message-count of given RabbitMQ queues. It use

🚀🏞💪 Collection of Images, Modifiers, utility functions for Jetpack Compose to expand and enrich displaying, manipulating, scaling, resizing, zooming, and getting cropped ImageBitmap based on selection area

Collection of Images, Modifiers, utility functions for Jetpack Compose to expand and enrich displaying, manipulating, scaling, resizing, zooming, and getting cropped ImageBitmap based on selection area, before/after image to with handle to show partial of both images and more is cooking up

Comments
  • support for both orientation.

    support for both orientation.

    I want to set dimen for both orientation. how should I do it?

    for eg. values-w483dp and values-w483dp-port automatically generated and the dimen values set to specific orientation.

    opened by kyawhtut-cu 3
Owner
Islam Khaled
Android Engineer
Islam Khaled
Cesar Valiente 1 Sep 3, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 27, 2022
An Android library for managing multiple stacks of fragments

FragNav Android library for managing multiple stacks of fragments (e.g., Bottom Navigation , Navigation Drawer). This library does NOT include the UI

Nic Capdevila 1.5k Jan 6, 2023
Sample to grasp screen transition flow using Navigation and BottomNavigationView.

NavigationFlowSample Navigation + BottomNavigationView を使用した画面遷移で、Destinationのフローを把握するためのサンプルです。 画面遷移時にバックグラウンドで動作しているの処理を切り替える際に有効かもしれません。 Code class

null 0 Oct 28, 2021
An application for conducting an experiment on the energy consumption of the screen on a test stand

energy-consumption-screen-test-app An application for conducting an experiment on the energy consumption of the screen on a test stand The Application

Motika Artem 0 Dec 10, 2021
🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.

Bubble Navigation ?? A light-weight library to easily make beautiful Navigation Bars with a ton of ?? customization options. Demos FloatingTopBarActiv

Gaurav Kumar 1.7k Dec 31, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Dec 26, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

AnimatedBottomBar A customizable and easy to use bottom bar view with sleek animations. Examples Playground app Download the playground app from Googl

Joery 1.2k Dec 30, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

Joery Droppers 1000 Dec 5, 2021
A small navigation library for Jetpack Compose with state saving, backstack and animations support.

A small navigation library for Jetpack Compose with state saving, backstack and animations support.

Xinto 5 Dec 27, 2022