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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:02:33+00:00 2026-05-18T05:02:33+00:00

I have a button. The button is constructed from the StateListDrawable (made of 3

  • 0

I have a button.
The button is constructed from the StateListDrawable (made of 3 9-patch images).
I need to add an extra drawable that will reside on the button’s right side, and i need it to be aligned with the button’s right side.
I tried to use the following:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/blue_back_button_drawable" />
    <item>
      <bitmap android:src="@drawable/filter_by_button_v_mark" android:gravity="right"/>
    </item>
</layer-list>

it didn’t work and the V image is indeed aligned right but it has a diff from the button’s right side. here’s a snapshot: alt text

I want the image to be aligned with the button’s left, the only way right now i think i can do it is:

  1. inherit button, in onLayout AFTER the width has been set get the right edge.
  2. get the background drawable (layerDrawable)
  3. calc the button’s width minus the v image width and set it as left margin in the drawable.

I should not mention this sounds horrid 🙂 i hoped there’s a better way. Oh the reason it’s not part of the image is that i need to know it’s width so i can calc the text padding so it wont be hidden by the button’s text and because it’s not so nice looking as a 9-patch.

  • 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-18T05:02:33+00:00Added an answer on May 18, 2026 at 5:02 am

    Seems like there was no proper solution to this. layer is for static and not 9-patch images apparently, or so it seems.
    So i extended Button, changed it’s on Draw, i have to use Canvas.restore() to break out of the margins that pushed my edges down and put my image in the upper right corner…
    here’s the code:

     @Override
    public void setPadding(int left, int top, int right, int bottom) {
        right += mImageWidth;
        super.setPadding(left, top, right, bottom);
    }
    
    private void setVImageDrawable(Drawable d) {
        mVImageDrawable = d;
        mImageWidth = mVImageDrawable.getIntrinsicWidth();
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if( mVImageDrawable != null && mIsMarked){
            //for some reason the clip binds us to position with margins, which is not so good for us.
            //we need to save the clip, restore the canvas to pre clipping mode, do what we need then
            //put the canvas back to it's previous clipping state.
            Rect bounds = canvas.getClipBounds();
            canvas.restore();
            int right = getRight();
            int left = right - mImageWidth;
            int top = getTop();
            int bottom = top + mVImageDrawable.getIntrinsicHeight();
            mVImageDrawable.setBounds(left, top, right, bottom);
            mVImageDrawable.draw(canvas);
            canvas.save();
            canvas.clipRect(bounds);
        }
    }
    

    If i don’t break out the original canvas iget ‘pushed down’ by any margins i add, it may also be fixed i think using xml property that specifies if children should be clipped on the layout containing this button, but i find that lame solution as it makes my button dependent on our conditions.
    The image itself i get from XML using new attributes and style and theme i declare.

    Hope it’ll help some ppl out there.

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

Sidebar

Related Questions

I have a button on an ASP.Net page that will call Response.Redirect back to
I have a button that I would like to disable when the form submits
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have a button on a website that creates a directory and copys a
I have a Button that is looking at 2 comboboxes to make sure they
I have a Swing application that I would like to convert from spaghetti to
I have a Qt main window that will pop up a dialog box that
Say I have a User Control in ASP.NET that contains a button: public class
I have a button class thats created from within the onSurfaceCreated method in my
I have a Button. Its View.OnClickHandler-implementing class is instantiated about 3 constructors deep from

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.