Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.view.View; public class Main { public static void setPaddingAll(View v, int paddingInDp) { v.setPadding(dpToPx(v.getContext(), paddingInDp), dpToPx(v.getContext(), paddingInDp), dpToPx(v.getContext(), paddingInDp), dpToPx(v.getContext(), paddingInDp)); } public static int dpToPx(Context context, float dp) { float density = context.getResources().getDisplayMetrics().density; return Math.round(dp * density); } }