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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:55:55+00:00 2026-06-07T19:55:55+00:00

I use a button with an image as its background, this image has a

  • 0

I use a button with an image as its background, this image has a size of 30×29, but it’s resized and enlarged x2 (I think). Here is the XML code of my button :

<Button
        android:id="@+id/buttonBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/bouton_back"
        android:maxHeight="30dp"
        android:maxWidth="30dp" />

And in Java :

backButton = (Button) findViewById(R.id.buttonBack);

What is wrong with that ? I do the same with other buttons and there is no problem… thank 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-06-07T19:55:56+00:00Added an answer on June 7, 2026 at 7:55 pm

    Are you supplying bouton_back in your resources using multiple densities? Using dp units to size your button isn’t sufficient; you must also provide multiple sizes of your images:

    • ldpi: 120dpi
    • mdpi: 160dpi
    • hdpi: 240dpi
    • xhdpi: 320dpi

    The conversion formula is as follows:

    px = dp * (dpi / 160)
    

    Where px is the final image size in pixels, dp is the desired size in density-independent units, and dpi is the target density.

    Simplifying this formula, using the size in pixels of your mdpi images as the baseline:

    ldpi = mdpi * 0.75
    hdpi = mdpi * 1.5
    xhdpi = mdpi * 2.0
    

    Going back to your sample code, if you want a button that is 30dp by 30dp, you should be providing images for each density:

    • ldpi: 23px x 23px
    • mdpi: 30px x 30px
    • hdpi: 45px x 45px
    • xhdpi: 60px x 60px
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I create button, use a background image that changes on hover and on
I have 5 buttons having a 9 patch image set as its background. but
I wanted to use a retina resolution image (40x40p) on a bar button item
I can use .button() to create beautiful submit buttons, but the rest of the
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
I am use a button and when u click this button a text field
I'm trying to use $(button).button(); but jquery-ui-1.8.16.custom.min.js used by SlickGrid doesn't have the button
I am trying to use a button in my init() method. <?xml version=1.0 encoding=utf-8?>
I am trying to achieve a button, which would look same (its background) no
I'm trying to make changing background image by menu item. It's works now but

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.