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;
Key Points to remember while develop the Android Application.
What is ANR in android?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Extract Date and Time from Long Type Variable - RRutors
How to reduce APK package size?
What happens next when the device switches between portrait and landscape?
How to save activity State in Android?
How to get a contact image using a phone number in android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to install/ uninstall apk by command line ADB
What is "shared preferences" in Android ?
What are the notifications available in android?
What is the difference between match_parent and fill_parent?
How to convert DP to Pixel and Pixel to Dp?
How do I check in SQLite whether a table exists?
How to copy database from assets folder in android using kotlin
Permission denied for window type 2010 in Marshmallow device
Open PDF in Google Drive with Intent in Android - RRutors
How to Exit android app on back pressed?
Fix Android Emulator Kill Error When Running Your App
How to get screen size (width,height) in Android?
How do I generate random numbers in Dart?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Check List for Generate Signed APK Android
What are Android Versions available?
What is Android Fragments?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Set Activity to Fullscreen Mode in Android - RRutors
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How To Set Text Color Programmatically Android TextView?
Add Jar/Library Files as Dependency in Android Studio
How to get an image resource by it's name in android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is the Different Between val and var in Kotlin?
Explain Fragment Life Cycle
Invoke-customs are only supported starting with android 0 --min-api 26
How to find Android Device UDID or unique ID?
How to start a new activity on button click
How to Get bitmap from drawable: Android
How to validate email address in Android with Kotlin?