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 to Exit android app on back pressed?
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Context?
How do i load image from drawable folder in Jetpack Compose?
Add Jar/Library Files as Dependency in Android Studio
Hide/Disable soft keyboard on Activity launch: Android
How to Use Deprecated Handler() in Android - RRutors Guide
How To Set Text Color Programmatically Android TextView?
How to start a new activity on button click
How to install/ uninstall apk by command line ADB
How to save activity State in Android?
Fix Android Emulator Kill Error When Running Your App
How do I check in SQLite whether a table exists?
What is Android?
Permission denied for window type 2010 in Marshmallow device
What is ANR? How to avoid and resolve it?
How to get a contact image using a phone number in android?
What happens next when the device switches between portrait and landscape?
How to Generate signed apk with android studio
How to get an image resource by it's name in android?
What is Android Fragments?
How do I generate random numbers in Dart?
Fix Play Store Rejection Due to SMS Permission - RRutors
What are the notifications available in android?
What is the difference between match_parent and fill_parent?
What is the Different Between val and var in Kotlin?
How to reduce APK package size?
How to check Android version?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to find Android Device UDID or unique ID?
What are Android Versions available?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
FCM Not Receiving Notifications in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Extract Date and Time from Long Type Variable - RRutors
Android Studio project R can't find
Set Activity to Fullscreen Mode in Android - RRutors