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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:11:17+00:00 2026-05-20T14:11:17+00:00

I have been struggling with what I think is something simple. I am setting

  • 0

I have been struggling with what I think is something simple. I am setting an image on an image button using a class. I want the image to fit the constraints of the screen, but without stretching. That is, if it’s too wide to fit the screen, I want the height to be scaled to accommodate so that it doesn’t get stretched. And if the height is too tall, I want the image height to be reduced, thereby shrinking the width too.

I have seen this question asked a couple times and I have tried every bit of the advice, but it makes absolutely no difference for me. I think this may have something to do with usnig an ImageButton instead of an ImageView?

Here are some relevant chunks of code (badly broken) …

In my class:

          ImageView img = (ImageButton) dialog.findViewById(R.id.fullsizeimage);
          img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);  //Changing ScaleType here has no effect
          img.setImageBitmap(useThisBitmap);

And here is the xml layout contents …

 <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<ImageButton
    android:id="@+id/fullsizeimage"
    android:background="@null"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    />

 </RelativeLayout>

Some of that junk in the XML file is probably wrong. But I have changed it so many times, and it has ZERO effect.

Any and all advise is greatly appreciated.

  • 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-20T14:11:18+00:00Added an answer on May 20, 2026 at 2:11 pm

    I think that ImageButton will always stretch the background image in order to fill its whole background.
    An ImageView can be easily made clickable on its own, have you tried that?

    A more complicated option is to use a custom view which can draw your image on canvas any way you like and can have onTouch listener.

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

Sidebar

Related Questions

I have been struggling to think of some decent uses for things like vectors
Using the vote_fu plugin for rails 3, I'm struggling with something (that I think)
I'm struggling with something that should be really easy I think. I have a
I have been struggling to get a simple autocomplete working with my Rails app
I have been struggling with this question for awhile now, and I haven't reached
I have been struggling with this for quite some time having been accustomed to
I have been struggling to find an answer to this theoretical question, even tho
I have been struggling with this for months in my project. Here's the deal:
I have been struggling with this yesterday whole day, and still couldnt figure it
I have been struggling with my customization of EditorForModel and the naming of HTML

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.