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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:58:34+00:00 2026-05-24T16:58:34+00:00

I’m trying to create a dynamic icon menu for my android application. The icon

  • 0

I’m trying to create a dynamic icon menu for my android application.
The icon is made from 2 drawable, a 9-patch background image with the icon image overlay on it.

With reference to overlay two images in android to set an imageview, I’ve the following code which have the overlay nicely.

        Resources res = parent.getResources();
        Drawable icon_bg = res.getDrawable(R.drawable.menu_icon_bg);
        Drawable icon = res.getDrawable(R.drawable.menu_icon);

        // Not working
        int int_icon_height = icon.getIntrinsicHeight();
        int int_icon_width = icon.getIntrinsicWidth();
        Rect rect_icon_bg_bound = new Rect();
        rect_icon_bg_bound.left = 0;//(int) Math.round(int_icon_width*-1.5);
        rect_icon_bg_bound.right = (int) Math.round(int_icon_width*1.5);
        rect_icon_bg_bound.top = 0;//(int)Math.round(int_icon_height*-1.5);
        rect_icon_bg_bound.bottom = (int)Math.round(int_icon_height*1.5);
        icon_bg.setBounds(rect_icon_bg_bound);

        Drawable[] layers = new Drawable[2];
        layers[0] = icon_bg;
        layers[1] = icon;

        LayerDrawable layerDrawable = new LayerDrawable(layers);
        ImageView iv_icon_combined = new ImageView(getApplicationContext());
        iv_icon_combined.setImageDrawable(layerDrawable);

The problem I’m facing right now is adding a padding so that the icon will have some spacing within the background.

Hope to get some enlightenment here, thanks in advance.

  • 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-24T16:58:35+00:00Added an answer on May 24, 2026 at 4:58 pm

    I just ran into this same issue. Take a look at the setLayerInset method on LayerDrawable. It takes the layer level as an argument and then the modifiers for the left, top, right, bottom bounds of the drawable.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.