The Android Arsenal – Gradle Plugins

[ad_1]

Help a number of display screen sizes simply by scaling your dimensions.

How does Xdimen work?

When you have got a UI design with a selected dimension, and it’s essential help completely different mobiles or tablets in portrait or panorama. This case Xdimen might help you to generate scalable dimesions for frequent gadgets’ display screen sizes.

Xdimen generates another res listing for each frequent display screen width (configurable) and scales your design dimensions.

Xml assets are generated with assist of kotlin xml builder

Discover extra about Xdimen right here

Utilization

Add to mission

Xdimen have to be utilized in an android mission.

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

Configure Xdimen

All properties are non-compulsory, solely designWidth is required. Properties are mentioned in additional element in beneath part.

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 assets (see subsequent part) you should utilize 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 mission utilizing one in all these methods

  • $ gradle :prjectName:taskName.
  • From gradle device window below android group.
  • From Run AnyThing window.

generateXdimen

Generates various assets for each gadget width in targetDevicesWidth set and for each created useful resource qualifier it scales the size to suit with this width. It makes use of configured properties to calculate a scaling issue, get the vary of dimensions to generate and the checklist of display screen widths’ to focus on.

deleteXdimen

Delete the earlier generated xdimen assets except you renamed the res file or dir. It is going to be executed earlier than generateXdimen should you set deleteOldXdimen property by true.

Configuration properties

deleteOldXdimen

By setting it once you execute generateXdimen job deleteXdimen will likely be executed first to delete all earlier generated xdimen assets and their dirs if the listing comprises solely xdimen.xml file.

In case you renamed the xdimen.xml file or its listing for any purpose, this file will not be deleted.

Default worth: true.

designWidth

The worth of display screen width of your design in dp unit. It is going to be used with designDpi to calculate the relativeDesignWidth (width relative to principal density mdpi) after which calculate a scaling issue for each display screen width in targetDevicesWidth.

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

No default worth as a result of it is required and have to be configured.

designDpi

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

Default worth is: mdpi

Predefined densities: for each density in frequent densities there is a technique with its title ( ldpi(), mdpi(), hdpi(), … and so on), Additionally there is a technique to set customized density dpi(worth).

targetDevicesWidth

The width of screens of gadgets which you goal. For each width on this checklist, another useful resource will likely be generated with scaled dimensions.

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

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

You should utilize a predefined set because it’s, provides or removes from it, or present your personal set.

Default worth is: [designWidth] set of designWidth offered worth.

Predefined units for frequent gadgets:

  • phonePortrait: frequent telephones in portrait orientation.
  • phoneLandscape: frequent telephones in panorama orientation.
  • tabletPortrait: frequent tablets in portrait orientation.
  • tabletLandscape: frequent tablets in panorama orientation.

  • devicesInPortrait: frequent telephones and tablets in portrait.
  • devicesInLandscape: frequent telephones and tablets in panorama.

You may mix a number of gadgets checklist, however I like to recommend to not goal each portrait and panorama except you present a customized format for panorama or utilizing Pane Structure.

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

dimensRange

The vary of dimensions you wish 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 identical of dimensRange however for fonts dimensions vary.

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

Screenshots

[ad_2]

Source_link