{"id":13605872,"url":"https://github.com/IslamKhSh/Xdimen","last_synced_at":"2025-04-12T05:35:00.537Z","repository":{"id":42654746,"uuid":"474494230","full_name":"IslamKhSh/Xdimen","owner":"IslamKhSh","description":"Easily support android multiple screen sizes","archived":false,"fork":false,"pushed_at":"2024-03-02T00:57:52.000Z","size":3517,"stargazers_count":50,"open_issues_count":0,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-02T19:38:48.153Z","etag":null,"topics":["android","dimensions","multiple-screen","ui-design"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IslamKhSh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-26T23:58:10.000Z","updated_at":"2024-03-25T12:55:05.000Z","dependencies_parsed_at":"2022-08-20T04:01:10.947Z","dependency_job_id":null,"html_url":"https://github.com/IslamKhSh/Xdimen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IslamKhSh%2FXdimen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IslamKhSh%2FXdimen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IslamKhSh%2FXdimen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IslamKhSh%2FXdimen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IslamKhSh","download_url":"https://codeload.github.com/IslamKhSh/Xdimen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223498078,"owners_count":17155254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dimensions","multiple-screen","ui-design"],"created_at":"2024-08-01T19:01:03.757Z","updated_at":"2024-11-07T10:31:24.842Z","avatar_url":"https://github.com/IslamKhSh.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Xdimen\n\n[![Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/io.github.islamkhsh.xdimen?color=blue\u0026logo=gradle)](https://plugins.gradle.org/plugin/io.github.islamkhsh.xdimen) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-Xdimen%20Gradle%20Plugin-gradle.svg?style=flat )]( https://android-arsenal.com/details/1/8408 )\n\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"images/xdimen%20logo.svg\" width=\"600\"\u003e\u003c/p\u003e\nSupport multiple screen sizes easily by scaling your dimensions.\n\n## How does Xdimen work?\n\nWhen you have a UI design with a specific dimension, and you need to support different mobiles or tablets in portrait or\nlandscape. This case **Xdimen** can help you to generate scalable dimesions for common devices' screen sizes.\n\nXdimen generates an alternative res directory for every common screen width (configurable) and scales your design\ndimensions.\n\n\u003e Xml resources are generated with help of [kotlin xml builder](https://github.com/redundent/kotlin-xml-builder)\n\nFind more about Xdimen [here](https://medium.com/@islam.khaled50/android-support-multiple-screen-sizes-by-scaling-dimensions-5fd9bd80821)\n\n\n## Usage\n\n![Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/io.github.islamkhsh.xdimen?color=blue\u0026logo=gradle\u0026label=Latest%20version)\n\n### Add to project\n\nXdimen must be applied in an android project.\n\n\u003cdetails\u003e\n\u003csummary\u003eGroovy\u003c/summary\u003e \n  \n````groovy\n  plugins {\n    id 'io.github.islamkhsh.xdimen' version \"$latest_version\"   \n    // agp plugin\n  } \n````\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n\u003csummary\u003eKotlin\u003c/summary\u003e \n  \n````kotlin\n  plugins {                         \n    id(\"io.github.islamkhsh.xdimen\") version \"$latest_version\"  \n    // agp plugin\n  }\n````\n\u003c/details\u003e\n\n### Configure Xdimen\nAll properties are optional, only `designWidth` is required. Properties are discussed in more detail in below section.\n\n\u003cdetails\u003e\n\u003csummary\u003eGroovy\u003c/summary\u003e \n  \n````groovy\n  xdimen {\n    deleteOldXdimen = true\n    designWidth = 411 // required\n    designDpi = mdpi()\n    targetDevicesWidth = [360, 375, 411]\n    dimensRange {\n        minDimen = -10\n        maxDimen = 600\n        step = 0.5d\n    }\n    fontsRange {\n        minDimen = 10\n        maxDimen = 60\n        step = 1.0d\n    }\n}\n````\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n\u003csummary\u003eKotlin\u003c/summary\u003e \n  \n````kotlin\n  xdimen {\n    deleteOldXdimen.set(true)\n    designWidth.set(411) // required\n    designDpi.set(mdpi())\n    targetDevicesWidth.set(phonePortrait)\n    dimensRange {\n        minDimen.set(-10)\n        maxDimen.set(500)\n        step.set(0.5)\n    }\n    fontsRange {\n        minDimen.set(10)\n        maxDimen.set(60)\n        step.set(1.0)\n    }\n}\n````\n\u003c/details\u003e \n\n### Use scaled dimens\nAfter generate xdimen resources (see next section) you can use the dimens \n```xml\n   \u003cTextView android:layout_width=\"@dimen/x100dp\"    # width in design is 100dp\n             android:layout_height=\"@dimen/x50_5dp\"  # height in design is 50.5dp\n             android:padding=\"@dimen/neg_x6_5dp\"     # padding in design is -6.5dp\n             android:textSize=\"@dimen/x12sp\"         # textSize in design is 12sp\n             /\u003e\n```\n\n## Tasks\n\nTo execute a task, make sure you execute it on an android project using one of these ways\n- `$ gradle :prjectName:taskName`.\n- From gradle tool window under `android` group.\n- From `Run AnyThing` window.\n\n### `generateXdimen`\n\nGenerates alternative resources for every device width in `targetDevicesWidth` set and for every created resource\nqualifier it scales the dimensions to fit with this width. It uses configured properties to calculate a scaling factor,\nget the range of dimensions to generate and the list of screen widths' to target.\n\n### `deleteXdimen` \n\nDelete the previous generated xdimen resources unless you renamed the res file or dir. It will be executed\nbefore `generateXdimen` if you set `deleteOldXdimen` property by true.\n\n## Configuration properties\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003edeleteOldXdimen\u003c/b\u003e\u003c/summary\u003e  \n\nBy setting it when you execute `generateXdimen` task `deleteXdimen` will be executed first to delete all previous\ngenerated xdimen resources and their dirs if the directory contains only `xdimen.xml` file.\n\n\u003e If you renamed the `xdimen.xml` file or its directory for any reason, this file won't be deleted. \n  \n\u003e Default value: **true**.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003edesignWidth\u003c/b\u003e\u003c/summary\u003e  \n\nThe value of screen width of your design in `dp` unit. It will be used with `designDpi` to calculate the\nrelativeDesignWidth (width relative to main density `mdpi`) and then calculate a scaling factor for every screen width\nin `targetDevicesWidth`.\n\n\u003e If your design is in `px` set its width in this property and set `designDpi` to be `mdpi` as in mdpi 1px = 1dp.\n\n\u003e No default value because it's required and must be configured.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003edesignDpi\u003c/b\u003e\u003c/summary\u003e  \n  \nThe design screen density (dot per inch) [see more](https://developer.android.com/training/multiscreen/screendensities). This will be used with `designWidth` to calculate the relativeDesignWidth.\n\n\u003e Default value is: **mdpi**\n\n\u003e Predefined densities: for every density in [common densities](https://developer.android.com/training/multiscreen/screendensities#TaskProvideAltBmp) there's a method with its name ( `ldpi()`, `mdpi()`, `hdpi()`, ... etc), Also there's a method to set custom density `dpi(value)`.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003etargetDevicesWidth\u003c/b\u003e\u003c/summary\u003e  \n\nThe width of screens of devices which you target. For every width in this list, an alternative resource will be generated\nwith scaled dimensions.\n\nex: if the list is [350, 400] then\n\n  ```\n  ...\n-\u003e values/xdimen.xml            # Devices with screen-width less than 350dp.\n-\u003e values-w350dp/xdimen.xml     # 350dp \u003c= screen-width \u003c 400dp\n-\u003e values-w400dp/xdimen.xml     # screen-width \u003e= 400dp\n  ...\n```\n  \n\u003e You can use  a predefined set as it's, adds or removes from it, or provide your own set.\n\n\u003e Default value is: **[designWidth]** set of designWidth provided value.\n\n\u003e \u003e Predefined sets for common devices:\n\u003e  - `phonePortrait`: common phones in portrait orientation.\n\u003e  - `phoneLandscape`: common phones in landscape orientation.\n\u003e  - `tabletPortrait`: common tablets in portrait orientation.\n\u003e  - `tabletLandscape`: common tablets in landscape orientation.\n\u003e  ####\n\u003e  - `devicesInPortrait`: common phones and tablets in portrait.\n\u003e  - `devicesInLandscape`: common phones and tablets in landscape.\n\u003e\n\u003e 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](https://developer.android.com/guide/topics/ui/layout/twopane).\n\u003e\n\u003e These lists were collected from many sources: [Wikipedia](https://en.wikipedia.org/wiki/Comparison_of_high-definition_smartphone_displays#720p_by_1280_(HD_ready)),\n[ScreenSize](https://screensiz.es/), [Pixensity](https://pixensity.com/list/) and others.\n\u003c/details\u003e\n  \n  \u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003edimensRange\u003c/b\u003e\u003c/summary\u003e  \n  \nThe range of dimensions you want to be generated and scaled.\n- `minDimen`: the minimum dimen to be generated.\n- `maxDimen`: the maximum dimen to be generated.\n- `step`: the step between two generated dimen.\n    \n\u003e Default value: **minDimen=-10**,  **maxDimen=600**,  **step=1.00**.\n\n\u003c/details\u003e\n\n   \u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003efontsRange\u003c/b\u003e\u003c/summary\u003e  \n\nThe same of `dimensRange` but for fonts dimensions range.\n\n\u003e Default value: **minDimen=6**,  **maxDimen=48**,  **step=1.00**.\n\n\u003c/details\u003e\n\n## Screenshots\n\n![screenshots](images/screenshots.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIslamKhSh%2FXdimen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIslamKhSh%2FXdimen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIslamKhSh%2FXdimen/lists"}