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;
How can i comment inside xml file in android studio?
Open PDF in Google Drive with Intent in Android - RRutors
How do I check in SQLite whether a table exists?
How to start a new activity on button click
What is "shared preferences" in Android ?
Add Jar/Library Files as Dependency in Android Studio
What is Application?
What is NetworkOnMainThread Exception?
What is Android Fragments?
What is ANR? How to avoid and resolve it?
How to reduce APK package size?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is Context?
Decompile APK Files: How to Get Source Code - RRutors Guide
How to Generate signed apk with android studio
How to check Android version?
Set Activity to Fullscreen Mode in Android - RRutors
Invoke-customs are only supported starting with android 0 --min-api 26
How to get a contact image using a phone number in android?
How to validate email address in Android with Kotlin?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Permission denied for window type 2010 in Marshmallow device
How to find Android Device UDID or unique ID?
What is Android?
How to Use Deprecated Handler() in Android - RRutors Guide
Fix Play Store Rejection Due to SMS Permission - RRutors
How to convert DP to Pixel and Pixel to Dp?
What is the Different Between val and var in Kotlin?
Check List for Generate Signed APK Android
How do i load image from drawable folder in Jetpack Compose?
How to save activity State in Android?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Hide/Disable soft keyboard on Activity launch: Android
Fix Android Emulator Kill Error When Running Your App
Extract Date and Time from Long Type Variable - RRutors
Android Studio project R can't find
How to convert milli seconds to hours, minutes and seconds in Android?
How do I generate random numbers in Dart?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is the difference between match_parent and fill_parent?