get Center Y Screen Position - Android User Interface

Android examples for User Interface:Screen Position

Description

get Center Y Screen Position

Demo Code


//package com.java2s;
import android.content.Context;

import android.graphics.Point;

import android.view.Display;

import android.view.WindowManager;

public class Main {
    public static float getCenterYScreenPosition(Context context) {
        Point p = getCenterScreenPosition(context);
        return p.y;
    }//  w w w  .j a v  a 2 s . c om

    public static Point getCenterScreenPosition(Context context) {
        Point p = getScreenSize(context);
        p.x = p.x / 2;
        p.y = p.y / 2;
        return p;
    }

    public static Point getScreenSize(Context context) {
        Display display = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size;
    }
}

Related Tutorials