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 6707705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:40:16+00:00 2026-05-26T07:40:16+00:00

I have the following layout for my ImageView : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

  • 0

I have the following layout for my ImageView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:descendantFocusability="blocksDescendants">
    <ImageView
        android:id="@+id/imageview_icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:scaleType="fitCenter" />
    (...)
</LinearLayout>

Those 48dp equal to 36px, 48px and 72px in ldpi, mdpi and hdpi respectively. All the images that will be used in this ImageView are basically icons and I’ve found on the web what I want for my app (free license). But unfortunately, it doesn’t come with images bigger than 48px and using different images is out of the question. So I need a new solution…

For now I have 36px and 48px images in the ldpi and mdpi folders, respectively. But I’m having trouble with hdpi. What I want for devices running on hdpi is for them to use the mdpi image (the bigger one available) and use it as it is, without scaling. Basically, the ImageView for hdpi is 72px, so I want the 48px image to be inside the 72px, in the center, without scaling. For that, I simply tried to change scaleType in the ImageView above to just center, but the image gets scaled anyway.

My ultimate question in here is, what’s the proper way to fix the problem described above? How can I have ldpi and mdpi images being used in their respective densities, but have devices running hdpi pick up the biggest image available (which is the mdpi ones) and prevent any scaling, just fitting the image in the center of the ImageView?

EDIT:
I answered this question myself, but it might to be the answer others coming here are looking for. But I do provide some insight on what’s really happening and the underlying problem. Please take a look and provide a workaround/fix if you can. I dare you 🙂

  • 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-26T07:40:17+00:00Added an answer on May 26, 2026 at 7:40 am

    This question turns out to be a non-question and I apologize to anyone that founds it, hoping the accepted answer will be what they are looking for when it won’t be.

    To make it clear, scaleType=centerInside is working as expected. That is, if you have an image smaller than the ImageView itself, than that image won’t be scaled to the bounds of the ImageView, it will remain in the center and unscaled.

    But for the above to work as expected, the drawable must be placed in the nodpi folder. I understand that this is not always acceptable. So, when that drawable must be placed into one of the density folders instead of the nodpi folder, the scaleType attribute will only work in specific situations.

    When it will work:

    • You are running the app on a device/emulator with Xdpi density and
      there is a drawable in the Xdpi density folder (here X means,
      l, m, h or even xh).
    • You are running the app device/emulator,
      for instance, with hdpi density, but there isn’t a drawable in the
      hdpi folder and the system picks the alternative drawable from the
      nodpi folder (it’s not always known which folder it will pick
      from).

    When it will not work:

    • You are running the app device/emulator, for instance, with hdpi
      density, but there isn’t a drawable in the hdpi folder and the
      system picks the alternative drawable from any other of the density
      folders (not the nodpi folder), the drawable will be scaled to the
      ImageView bounds and the scaleType attribute will not do
      anything.

    In conclusion, there’s no “right” answer to my question, it really depends on what you are trying to achieve. The answer my question though, I just need to do 2 things: a) Set the ImageView scaleType to centerInside and b) Duplicate all drawables from the mdpi folder into the hdpi folder (as explained above, the scaleType=centerInside will make it work).

    Of course, duplicating drawables is not optimal, but I can’t find any other solution and so far, no one else could either… So, in the time being, I’ll mark this one as accepted.

    What would be the optimal answer/solution then?
    In my opinion, if the device/emulator is running in hdpi and there isn’t a matching drawable in the hdpi folder it should be pick the drawable from the mdpi folder without scaling it, allowing the scaleType attribute to do it’s thing. Or maybe force the system to go to the nodpi folder if it doesn’t find a matching drawable in the respective density folder, that could a solution too.

    So, if anyone can ever provide a workaround/fix to this issue, that would be the real correct answer. If it ever comes to that, I’ll change the accepted status.

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

Sidebar

Related Questions

I have the following XML layout for a ListActivity. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have the following layout in XML (splashscreen.xml): <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/frmLayout
I have the following layout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical android:background=#EAEAEA>
I have the following main.xml file with a LinearLayout <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout android:id=@+navigate/RLayout android:layout_width=fill_parent android:layout_height=fill_parent android:background=#ABABAB xmlns:android=http://schemas.android.com/apk/res/android
I have a very simple Android activity layout like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have the following layout defined for one of my Activities: <?xml version=1.0 encoding=utf-8?>
I have done my custom ListView, the xml was following: <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have a simple LinearLayout in Android with two images vertically: <?xml version=1.0 encoding=utf-8?>

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.