Convert dip to px - Android android.content

Android examples for android.content:Context

Description

Convert dip to px

Demo Code

import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }/*from w  w  w.  j  a v  a  2  s.  c  o  m*/

}

Related Tutorials