Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.content.res.Resources;

public class Main {
    /**
     * Converte de DIP para Pixels
     */
    public static float toPixels(Context context, float dip) {
        Resources r = context.getResources();
        //int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());

        float scale = r.getDisplayMetrics().density;
        int px = (int) (dip * scale + 0.5f);

        return px;
    }
}