Skip to content

This library is used in jetpack compose to overcome UI differences in different android devices for same code.

Notifications You must be signed in to change notification settings

mohitsoni48/aDp

Repository files navigation

aDp

See here why you need this: https://medium.com/@mohitsoni48/creating-pixel-perfect-ui-with-jetpack-compose-17376455f16b

How to Install

Add it in your root build.gradle at the end of repositories:

dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add the dependency

dependencies {
	implementation 'com.github.mohitsoni48:aDp:<Version>'
}

How to Use

Initialize ADp in you application class/ Launching Activity like this

ADp.initializeAdp(this.resources, <Your design width in px>)

Replace dp with aDp and sp with aSp in your Jetpcak Compose

Text(
     text = "This text uses aSp\nDimensions to box are in aDp",
     fontSize = 16.aSp,
     modifier = Modifier
     .background(
        Color.LightGray
     )
     .padding(vertical = 20.aDp)
     .width(300.aDp)
)

Liked my work?

ko-fi

Note: This library is not optimized for foldable phones and tablets. Also If your device supports configuration changes, you will need to initialize again on each configuration change