get View Location - Android User Interface

Android examples for User Interface:View Position

Description

get View Location

Demo Code


//package com.java2s;

import android.graphics.Point;
import android.support.annotation.NonNull;
import android.view.View;

public class Main {
    public static Point getViewLocation(@NonNull View view) {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        int centerX = location[0];
        int centerY = location[1];

        return new Point(centerX, centerY);
    }//from  w  ww  .j av a  2s.c o m
}

Related Tutorials