Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:38:21+00:00 2026-05-27T03:38:21+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:38:22+00:00Added an answer on May 27, 2026 at 3:38 am

    The relevant member variables of the ImageView are mMaxWidth and mMaxHeight, 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:

    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();
    }
    

    The other answers mention getWidth() and getHeight(), 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):

    Log.d("TEST", "width="+iv.getWidth()+" || height="+iv.getHeight());
    Log.d("TEST", "maxWidth="+maxWidth+" || maxHeight="+maxHeight);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ImageView <ImageView android:id=@+id/auto android:layout_width=wrap_content android:layout_height=wrap_content android:layout_margin=10sp android:src=@drawable/auto /> How can I
I have this ImageView block inside a Relative layout: <ImageView android:layout_width=wrap_content android:layout_height=wrap_content android:layout_alignParentBottom=true android:layout_marginBottom=50dip
I am new to android.I have a image which is declared in xml file
I have an ImageView that is defined in the following way: <ImageView android:id=@+id/cover_view android:layout_width=wrap_content
I have an ImageView with a source image set in the xml using the
I have an ImageView declared in main.XML . I want it to be Zoomed
I need a way to have a gray scale image in an ImageView and
I have an ImageView in my application and I am loading the image in
I have a Imageview in main.xml, how to set the bitmap the to the
I have an ImageView in my android layout. And I would like to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.