To Convert dp to px or px to dp fisrt we need to calculate device Density DPI Lets create DisplayMetrics object DisplayMetrics displayMetrics= getResources().getDisplayMetrics(); Now calculate devie Density DPI float densityDpi=displayMetrics.densityDpi; Convert dp to px dp*(densityDpi/defaultDPI); Convert px to dp px*(densityDpi/defaultDPI);
we will get density DPI fromDisplaymetrics object.
float defaultDPI=DisplayMetrics.DENSITY_DEFAULT;
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How to Get bitmap from drawable: Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Permission denied for window type 2010 in Marshmallow device
How to save activity State in Android?
How do i load image from drawable folder in Jetpack Compose?
Invoke-customs are only supported starting with android 0 --min-api 26
What is Android Fragments?
How to stop EditText focus at Activity startup in Android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
How to avoid multiple button click at same time in android?
How to convert milli seconds to hours, minutes and seconds in Android?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
What is the difference between match_parent and fill_parent?
How to check Android version?
How to validate email address in Android with Kotlin?
What is ANR? How to avoid and resolve it?
How to copy database from assets folder in android using kotlin
What are Android Versions available?
How to convert DP to Pixel and Pixel to Dp?
What happens next when the device switches between portrait and landscape?
How to install/ uninstall apk by command line ADB
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
How to get a contact image using a phone number in android?
What is "shared preferences" in Android ?
How do I generate random numbers in Dart?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How can i comment inside xml file in android studio?
What is the Different Between val and var in Kotlin?
What is Intent? What is the difference between an implicit intent and an explicit intent?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to Generate signed apk with android studio
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
What is NetworkOnMainThread Exception?
How to Exit android app on back pressed?
How to get complete address from latitude and longitude?
How to find Android Device UDID or unique ID?
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What is ANR in android?
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?