Make stronger a couple of display sizes simply by means of scaling your dimensions.
How does Xdimen paintings?
In case you have a UI design with a particular measurement, and you want to strengthen other mobiles or capsules in portrait or panorama. This situation Xdimen help you to generate scalable dimesions for not unusual gadgets’ display sizes.
Xdimen generates another res listing for each and every not unusual display width (configurable) and scales your design dimensions.
Xml sources are generated with assist of kotlin xml builder
In finding extra about Xdimen right here
Utilization
Upload to venture
Xdimen will have to be carried out in an android venture.
Groovy
plugins {
identity 'io.github.islamkhsh.xdimen' model "$latest_version"
// agp plugin
}
Kotlin
plugins {
identity("io.github.islamkhsh.xdimen") model "$latest_version"
// agp plugin
}
Configure Xdimen
All houses are not obligatory, simplest designWidth
is needed. Homes are mentioned in additional element in beneath phase.
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 sources (see subsequent phase) you’ll be able to use the dimens
<TextView android:layout_width="@dimen/x100dp" # width in design is 100dp
android:layout_height="@dimen/x50_5dp" # top 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
/>
Duties
To execute a job, be sure to execute it on an android venture the usage of this type of tactics
$ gradle :prjectName:taskName
.- From gradle device window underneath
android
team. - From
Run AnyThing
window.
generateXdimen
Generates selection sources for each and every instrument width in targetDevicesWidth
set and for each and every created useful resource qualifier it scales the scale to suit with this width. It makes use of configured houses to calculate a scaling issue, get the variety of dimensions to generate and the record of display widths’ to focus on.
deleteXdimen
Delete the former generated xdimen sources except you renamed the res report or dir. It’ll be performed ahead of generateXdimen
for those who set deleteOldXdimen
assets by means of true.
Configuration houses
deleteOldXdimen
Via atmosphere it whilst you execute generateXdimen
process deleteXdimen
might be performed first to delete all earlier generated xdimen sources and their dirs if the listing accommodates simplest xdimen.xml
report.
If you happen to renamed the
xdimen.xml
report or its listing for any reason why, this report would possibly not be deleted.
Default worth: true.
designWidth
The worth of display width of your design in dp
unit. It’ll be used with designDpi
to calculate the relativeDesignWidth (width relative to major density mdpi
) after which calculate a scaling issue for each and every display width in targetDevicesWidth
.
In case your design is in
px
set its width on this assets and setdesignDpi
to bemdpi
as in mdpi 1px = 1dp.
No default worth as a result of it is required and will have to be configured.
designDpi
The design display density (dot consistent with inch) see extra. This might be used with designWidth
to calculate the relativeDesignWidth.
Default worth is: mdpi
Predefined densities: for each and every density in not unusual densities there is a means with its title (
ldpi()
,mdpi()
,hdpi()
, … and so forth), Additionally there is a technique to set customized densitydpi(worth)
.
targetDevicesWidth
The width of displays of gadgets which you goal. For each and every width on this record, another useful resource might be generated with scaled dimensions.
ex: if the record is [350, 400] then
...
-> values/xdimen.xml # Units with screen-width not up to 350dp.
-> values-w350dp/xdimen.xml # 350dp <= screen-width < 400dp
-> values-w400dp/xdimen.xml # screen-width >= 400dp
...
You’ll be able to use a predefined set as it is, provides or eliminates from it, or supply your personal set.
Default worth is: [designWidth] set of designWidth supplied worth.
Predefined units for not unusual gadgets:
phonePortrait
: not unusual telephones in portrait orientation.phoneLandscape
: not unusual telephones in panorama orientation.tabletPortrait
: not unusual capsules in portrait orientation.tabletLandscape
: not unusual capsules in panorama orientation.
devicesInPortrait
: not unusual telephones and capsules in portrait.devicesInLandscape
: not unusual telephones and capsules in panorama.You’ll be able to mix a couple of gadgets record, however I like to recommend to not goal each portrait and panorama except you supply a customized format for panorama or the usage of Pane Structure.
Those lists had been gathered from many assets: Wikipedia, ScreenSize, Pixensity and others.
dimensRange
The variability of dimensions you wish to have to be generated and scaled.
minDimen
: the minimal dimen to be generated.maxDimen
: the utmost dimen to be generated.step
: the step between two generated dimen.
Default worth: minDimen=-10, maxDimen=600, step=1.00.
fontsRange
The similar of dimensRange
however for fonts dimensions vary.
Default worth: minDimen=6, maxDimen=48, step=1.00.