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

  • Home
  • SEARCH
  • 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 8489121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:44:19+00:00 2026-06-10T21:44:19+00:00

I have a ListView whose items are ImageView s, for the sake of discussion.

  • 0

I have a ListView whose items are ImageViews, for the sake of discussion. I want the image to scale to the width of the ListView‘s rows, and maintain it’s aspect ratio. here’s a simplified version of the ListView‘s item layout,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="4dp" >

        <FrameLayout
            android:id="@+id/page_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="visible" >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter"
                android:src="@drawable/some_image" />
        </FrameLayout>
    </FrameLayout>

</LinearLayout>

the ImageView‘s width is match_parent, and all ancestors of it are the same. Layout designer shows that the ImageView‘s dimensions span the entire width, but the image inside does not.

The image is scaling correctly. The problem is that the height of the list view row is such that the width can’t scale to the right size. If I use fitXY, it does scale the width, but then the aspect ratio is incorrect.

Any ideas?

  • 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-06-10T21:44:20+00:00Added an answer on June 10, 2026 at 9:44 pm

    I couldn’t find any way to accomplish this without creating a custom view. in a nutshell, the custom view sets it’s own dimensions to the real (not scaled) dimensions of the drawable behind it.

    public class ResizableImageView extends ImageView {
    
        public static interface OnSizeChangedListener {
    
            void onSizeChanged(int width, int height);
        }
    
        private OnSizeChangedListener onSizeChangedListener = null;
    
        public ResizableImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
            setMeasuredDimension(width, height);
            if (onSizeChangedListener != null) {
                onSizeChangedListener.onSizeChanged(width, height);
            }
        }
    
        public void setOnSizeChangedListener(OnSizeChangedListener listener) {
            this.onSizeChangedListener = listener;
        }
    }
    

    In my case I needed to obtain the resized value in order to size the other views, hence the listener interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView whose size is fixed to maximum of 10 items View
What my application first does is it loads ListView whose items have invisible CheckBoxes
I am developing an app in which I need a ListView whose rows have
In my application, I have a listview whose list item consists of a TextView
I have a ListView whose ItemsSource is bound to an ObservableCollection. The collection is
I have listview control.There is an option to remove selected items.After the user removes
I have listview having customized some textview and one imageview. When I long click
I have a ListView with Horizontal WrapPanel as its ItemsPanelTemplate. I want to get
In jQueryMobile, I have written a data-role=listview component and I want to filter the
I have a custom ListView and an ImageView that I'm trying to use as

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.