int dpValue = 5; // margin in dips
float d = context.getResources().getDisplayMetrics().density;
int margin = (int)(dpValue * d); // margin in pixels
More Related Contents:
- Android Studio layout editor cannot render custom views
- How to construct a button on runtime (Android) [closed]
- View’s getWidth() and getHeight() returns 0
- Changing EditText bottom line color with appcompat v7
- How to programmatically set drawableLeft on Android button?
- Android Studio Error: Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you’re running
- Android: how to change the color of the datepicker divider?
- ‘Source code does not match the bytecode’ when debugging on a device
- Android Studio was unable to find a valid Jvm (Related to MAC OS)
- Android Studio TransformException : Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’
- NetworkSecurityConfig: No Network Security Config specified — Android 7.0 error?
- == and .equals() not working in java [duplicate]
- Android: why setVisibility(View.GONE); or setVisibility(View.INVISIBLE); do not work
- Portrait for phone, landscape for Tablet (Android-Layout)
- How to create Button Dynamically in android?
- IntelliJ Build Error Context Mismatch
- How to fix the ”module java.base does not “opens java.io” to unnamed module ” error in Android Studio?
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- Exporting and running Unity3D project to Android Studio
- Android Studio Build gradle OutOfMemoryError
- Android: How to configure FFMPEG latest version in android studio?
- How to add Three Level ListView in ExpandableListView in android
- How to set layout dynamically in android
- Error:Timeout waiting to lock buildscript class cache for build file when change minSdkVersion
- Error: Could not find com.google.gms:google-services:1.0. when adding google service plugin in build.gradle in android studio
- Creating LinearLayout Programmatically/Dynamically with Multiple Views
- Recycler view – resizing item view while scrolling (for carousel like effect)
- Unity3D and Android Studio Integration
- Spinner’s scrollbar style
- Error:Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler