Anu
Anu

Reputation: 31

Getting screen size and use in drawbit map

This is not my activity! this is separate class file i am using Surface view extended to my class file . i wanted to display a small bit map to my canvas my bit map is very small than my phone screen so i used a createscaledbitmap to fit it in my phone screen with this code here

  Bitmap  o2 = Bitmap.createScaledBitmap( hud, 800, 490, false);

it worked great in my phone but when i tested in a bigger phone i have my bitmap pasted only 3/4 of the screen .. so i want to make my bitmap to fix the phone screen size

Bitmap  o2 = Bitmap.createScaledBitmap( hud, phonescreenwidth, phonescreenheight, false);

is there a function to get the phone display size and use in my code ? like
int phonescreenwidth = surfaceView.getwidth ();

and there is a function called protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) i dont know how to use it . if someone know please tell me how too :)

Thank you all

Upvotes: 0

Views: 96

Answers (3)

user1831682
user1831682

Reputation:

try this to get Screen size,,

Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight();

then try passing context from ur baseActivity to the current activity

and then try context.getWindowManger....

Upvotes: 0

Jayasagar
Jayasagar

Reputation: 2066

DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels;

Refer here http://developer.android.com/guide/practices/screens_support.html#testing

and

Get screen dimensions in pixels

Upvotes: 1

kalyan pvs
kalyan pvs

Reputation: 14590

BY this way you can get width and height of your device and pass it in your method..

WindowManager manager = (WindowManager) getApplicationContext().getSystemService(Activity.WINDOW_SERVICE);
    int width, height;
    LayoutParams params;
    if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
        width = manager.getDefaultDisplay().getWidth();
        height = manager.getDefaultDisplay().getHeight();
    } else {
        Point point = new Point();
        manager.getDefaultDisplay().getSize(point);
        width = point.x;
        height = point.y;
    }

Upvotes: 1

Related Questions