I have ImageView declared at xml:
...
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="60dip"
android:maxWidth="60dip"
android:scaleType="centerCrop" />
...
And I want to get maxWidth and maxHeight paramater values programmatically:
...
ImageView imageView = (ImageView) findViewById(R.id.image);
int maxWidth = ?
int maxHeight = ?
...
How can I do it?
The relevant member variables of the ImageView are
mMaxWidthandmMaxHeight, both are declared private. There are also no getter methods available, which leaves you with one option:Use reflection to inspect the fields.
Here is a sample how to do that:
The other answers mention
getWidth()andgetHeight(), but it’s not the same. If you run the following snippet after the inspection above you will see differences (given that the size and the max size are not identical at the moment due to the set values or the source image size):