Xdimen 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
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 />