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;
What happens next when the device switches between portrait and landscape?
How to convert DP to Pixel and Pixel to Dp?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How to validate email address in Android with Kotlin?
Android Studio project R can't find
How to Generate signed apk with android studio
How to get complete address from latitude and longitude?
What is the difference between match_parent and fill_parent?
What is Context?
How to save activity State in Android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
How to add jar/library files as a dependency in Android studio gradle file
How do I check in SQLite whether a table exists?
What is Application?
How to convert milli seconds to hours, minutes and seconds in Android?
What is ANR in android?
Check List for Generate Signed APK Android
How do I generate random numbers in Dart?
How to avoid multiple button click at same time in android?
How To Set Text Color Programmatically Android TextView?
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
How to Get bitmap from drawable: Android
Hide/Disable soft keyboard on Activity launch: Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Android FCM not receiving notifications when app is removed from background
How to extract date and time from Long type variable in Kotlin on Android "
What is Android Fragments?
What are the notifications available in android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Duplicate files during packaging of APK” build.gradle issue: Android Studio
Explain Fragment Life Cycle
What is Android?
How to start a new activity on button click
How to find Android Device UDID or unique ID?
What is the Different Between val and var in Kotlin?
How to stop EditText focus at Activity startup in Android?
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
How to check Android version?
Permission denied for window type 2010 in Marshmallow device