get Image Button Size - Android User Interface

Android examples for User Interface:ImageButton

Description

get Image Button Size

Demo Code


//package com.java2s;

import android.app.Activity;

import android.util.DisplayMetrics;

public class Main {
    private static int mImageButtonSize = -1;

    public static int getImageButtonSize(Activity activity) {
        if (mImageButtonSize == -1) {
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay()
                    .getMetrics(metrics);

            switch (metrics.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                mImageButtonSize = 16;/*from   w  w  w. ja  v  a  2  s.  co m*/
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                mImageButtonSize = 32;
                break;
            case DisplayMetrics.DENSITY_HIGH:
                mImageButtonSize = 48;
                break;
            default:
                mImageButtonSize = 32;
            }
        }

        return mImageButtonSize;
    }
}

Related Tutorials