The corresponding ImageView member variables are mMaxWidth
and mMaxHeight
, both declared private. Available getter methods are also not available that leave you with one of the options:
Use reflection to check the fields.
Here is an example of how to do this:
int maxWidth = -1; int maxHeight = -1; ImageView iv = (ImageView) findViewById(R.id.imageview); try { Field maxWidthField = ImageView.class.getDeclaredField("mMaxWidth"); Field maxHeightField = ImageView.class.getDeclaredField("mMaxHeight"); maxWidthField.setAccessible(true); maxHeightField.setAccessible(true); maxWidth = (Integer) maxWidthField.get(iv); maxHeight = (Integer) maxHeightField.get(iv); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }
Other answers mention getWidth()
and getHeight()
, but this is not the same. If after checking you run the following snippet, you will see the differences (given that the size and maximum size are not identical at the moment due to the set values ββor the size of the original image):
Log.d("TEST", "width="+iv.getWidth()+" || height="+iv.getHeight()); Log.d("TEST", "maxWidth="+maxWidth+" || maxHeight="+maxHeight);
user658042
source share