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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:08:56+00:00 2026-05-25T21:08:56+00:00

I want to draw a border around an image. But I can’t align the

  • 0

I want to draw a border around an image. But I can’t align the border at the ImageView itself (like it is done mostly) because I translate and scale the image inside of the ImageView with the ImageMatrix (the ImageView itself is fill_parent / fills the whole screen). I had the idea to add a second image (which looks like a border) and translate & scale it in the same way as the image which should have a border, but it isn’t very handy to do it this way.
Has anybody a better idea to reach that goal?

  • 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-25T21:08:56+00:00Added an answer on May 25, 2026 at 9:08 pm

    There are two ways to achieve this:
    1) add padding to the imageView and set a background color to it.

    final ImageView imageView = new ImageView(context);
    imageView.setPadding(2*border,2*border,0,0);
    final ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(width,height);
    params.leftMargin = marginYouWouldSet + border;
    params.topMargin = marginYouWouldSet + border;
    imageView.setBackgroundDrawable(drawable);
    imageView.setBackgroundColor(borderColor);
    addView(imageView, params);
    

    2) another option is to override the draw method of your view and there draw the border:

    @Override
    protected void dispatchDraw(Canvas canvas)
    {
     borderDrawable.draw(canvas);
     super.dispatchDraw(canvas);
    }
    ...
    public class BorderDrawable extends Drawable{
    
        private Rect mBounds;
        private Paint mBorderPaint;
    
        public BorderDrawable(Rect bounds, int thickness, int color) {
            mBounds = bounds;
            mBorderPaint = new Paint();
            mBorderPaint.setStrokeWidth(thickness);
            mBorderPaint.setColor(color);
        }
    
        @Override
        public void draw(Canvas canvas) {
            //left border
            canvas.drawLine(
                    mBounds.left - thickness/2, 
                    mBounds.top,
                    mBounds.left - thickness/2,
                    mBounds.bottom,
                    mBorderPaint);
            //top border
            canvas.drawLine(
                    mBounds.left, 
                    mBounds.top - thickness/2,
                    mBounds.right, 
                    mBounds.top - thickness/2, 
                    mBorderPaint);
            //right border
            canvas.drawLine(
                    mBounds.right + thickness/2, 
                    mBounds.top,
                    mBounds.right + thickness/2,
                    mBounds.bottom, 
                    mBorderPaint);
            //bottom border
            canvas.drawLine(
                    mBounds.left, 
                    mBounds.bottom + thickness/2, 
                    mBounds.right, 
                    mBounds.bottom + thickness/2, 
                    mBorderPaint);
        }
    
    }
    

    Note that you are to give the middle of the line you want to draw(!) And also I haven’t run, nor compiled this, so I’m not 100% sure it’s correct, but these are the ways 🙂 Rect bounds should be the bounding rect of your view – (0,0,width,height).

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

Sidebar

Related Questions

I have subclasses NSImageView and i want to draw a border around with rounded
I want to draw string using Graphics with Rectangle border outside the string. This
I want to draw some Rectangle over a single Image . For example I
I have a bit of code that I use to draw a border around
I want to draw a triangle as a border background. One way of doing
I have a widget and I want to draw an orange frame around a
I want to draw the themed border of a TEdit in a Paintbox. The
I want to be able to draw a border OUTSIDE of my Div! So
I want to draw rectangle that is only specified percent high of panel im
I want to draw circle, and i want to re size it based on

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.