Get position of imageview on layout android

26,126

Solution 1

You can use this with getLocationOnScreen(int [])

Solution 2

x = imageViewObject.getLeft();
y = imageViewObject.getTop();

Hope, it help you!

Solution 3

At runtime you can get the location of every View object (this includes Layouts too) with

Left Position of View Object getleft()

Top Position of View Object getTop()

Right Position of View Object getRight()

Bottom Position of View Object getBottom()

Even you can get the location with

getLocationOnScreen(int [] )

Solution 4

Position meaning x and y and height and width?

This layout is a view, that view has these properties.

Share:
26,126
Programmer
Author by

Programmer

Android and Windows Mobile developer

Updated on April 24, 2020

Comments

  • Programmer
    Programmer about 4 years

    Please help me i want to get position of imageview on a layout.

    enter image description here

  • Programmer
    Programmer over 12 years
    i want to get current location on view means x and y corrdinate, so that i can animate from this position to that position.
  • JoxTraex
    JoxTraex over 12 years
    Look at the methods available in the View class.
  • mathheadinclouds
    mathheadinclouds over 9 years
    didn't work for me. Everything returned zero. (Used with Button, not ImageView, but that shouldn't make a difference.)
  • Lasitha Lakmal
    Lasitha Lakmal over 4 years
    not work for me. my image with is in a RelativeLaoyout and it relates with a button from the top and aligns with the right
  • DIRTY DAVE
    DIRTY DAVE about 4 years
    @mathheadinclouds doesn't work for me either. Did you ever get a work around?
  • Johannes Pertl
    Johannes Pertl almost 4 years
    Still no solution? It's 0 for me too