-1

I have an ImageView with height and width as 360dp and 360dp.

But in my Java class if I try to get the height and width, it gives different values -

ImageView graph = (ImageView)findViewById(R.id.graph);
    float he = graph.getMeasuredHeight();
    float wi = graph.getMeasuredWidth();
    Log.d("height of view", ""+he);
    Log.d("width of view", ""+wi);

the output is

height of view: 540
width of view: 480

What is the reason ? How should i get equal correct values ?

I'm using a Relative Layout.

Ronn
  • 183
  • 2
  • 13
  • 1
    `I have an ImageView with height and width as 360dp and 360dp` I see you still don't have clear the difference between **dp** and **px**... – Phantômaxx Aug 13 '15 at 11:48
  • I'm voting to close this question as off-topic because it lacks some minimal study about the typical Android measuring units. – Phantômaxx Aug 13 '15 at 11:50
  • Check this : http://stackoverflow.com/questions/10411975/how-to-get-the-width-and-height-of-an-image-view-in-android – SANAT Aug 13 '15 at 11:51

2 Answers2

1

Just add this in your Imageview android:adjustViewBounds="true" Finally,

<ImageView
android:adjustViewBounds="true"
android:src="@drawable/"

/>

After that,you use getWidth(); And getHeight(); Method (PX Unit)

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Your imageview is fitting to your image ,you can set attribute

android:scaleType="centerCrop"
mFarouk
  • 11
  • 4