get View Layout X - Android User Interface

Android examples for User Interface:Layout

Description

get View Layout X

Demo Code


//package com.java2s;

import android.graphics.Rect;
import android.view.View;

public class Main {
    public static int getLayoutX(View view) {
        int[] location = new int[2];
        Rect rect = new Rect();
        view.getLocalVisibleRect(rect);/*from  www  .j  a v  a2  s  .c  o  m*/
        view.getLocationInWindow(location); 
        view.getLocationOnScreen(location);
        return location[0];
    }
}

Related Tutorials