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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:20:48+00:00 2026-06-16T15:20:48+00:00

When using a 9-patch image as a background, the padding seems to be always

  • 0

When using a 9-patch image as a background, the padding seems to be always derived from the 9-patch image. Even if you do not use a padding bar in the 9 patch image it uses the drawable.

If the padding lines are not included, Android uses the left and top lines to define this drawable area.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

However you can override it in the XML by using android:padding=0dp or =Xdp.
Unfortunately using android:paddingLeft=Xdp does not work. So you are stuck with uniform padding.
I tried doing this:

  android:padding="2dp"
  android:paddingLeft="20dp"

It had no effect on the padding on the left. Placing them in a styles.xml produced similar results.

The only hack I have seen to get around this was to set the padding in code.

  • 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-16T15:20:50+00:00Added an answer on June 16, 2026 at 3:20 pm

    if (android:padding presented) it overrides all other padding values
    else if (android:paddingXXX presented) it overrides bg drawable paddingXXX (XXX = Left|Right|Top|Bottom)
    else if (view has drawable bg) padding values from this drawable (nine-patch in your case) will be used
    else default padding will be applied (zero usually)

    So do no use android:padding=”2dp”. padding property overrides everything. Just use paddingLeft = 20dp, paddingTop = 2dp, paddingRight = 2dp, paddingBottom = 2dp.

    Or you can set paddingLeft = 20dp and other padding values will be taken from bg drawable.

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

Sidebar

Related Questions

I encountered this problem when updating my background to use a 9-patch image. The
I am using jquery for changing image path but its not working for asp.net
i can pick a image and its path using intent. with the use of
I'm trying to create a new spinner background using a 9 patch picture. I've
I am trying to make tiles for a game using a larger background image
I am trying to set a 9-patch image as the background for one of
I'm using minify and now I have css file style.css body{ background: url(image.png); }
I got this div tag who's background image's being set in the CSS using
I have 5 buttons having a 9 patch image set as its background. but
I am having scaling problems when using the 9-patch images for the background of

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.