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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:49:13+00:00 2026-05-26T04:49:13+00:00

I have an image which I’m using as a background for a RelativeLayout. The

  • 0

I have an image which I’m using as a background for a RelativeLayout. The image needs to be tiled horizontally to make a pattern.

I’m able to get the image to tile horizontally by using this code:

BitmapDrawable b3 = (BitmapDrawable)getResources().getDrawable(R.drawable.background);

b3.setTileModeX(Shader.TileMode.REPEAT);

v.findViewById(R.id.layout).setBackgroundDrawable(b3);

The problem is that the image also tiles vertically. It seems to tile in the “clamp” mode in the vertical, but “repeat” mode in the horizontal. Here is a screenshot:

TileMode

As you can see, the image is just a little bit smaller than the space it occupies, and the bottom edge is “clamped”.

How can I set the image to stretch vertically but tile horizontally?

  • 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-26T04:49:13+00:00Added an answer on May 26, 2026 at 4:49 am

    This method invokes creation of new bitmap but it looks like it’s acrhiving your goal

            View view = findViewById(R.id.layout);
            BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.tile);
            int width = view.getWidth();
            int intrinsicHeight = bd.getIntrinsicHeight();
            Rect bounds = new Rect(0,0,width,intrinsicHeight);
            bd.setTileModeX(TileMode.REPEAT);
            bd.setBounds(bounds);
            Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), bd.getBitmap().getConfig());
            Canvas canvas = new Canvas(bitmap);
            bd.draw(canvas);
            BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
            view.setBackground(bitmapDrawable);
    

    Please note that it only works if view was already layouted, so a method lile onWindowFocusChanged is a good place for this code.

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

Sidebar

Related Questions

I have an image uploader and cropper which creates thumbnails and I occasionally get
I have and image which gets stretched to its full background, regardless of the
I am using asp.net 3.5 and C#. I have a image which I want
I need to get a trimmed CGImage. I have an image which has empty
I have an image which is intended to be a background image, which fills
I have a background image which i need to display vertically as long as
I have an image which moves horizontally with a given speed over a delta
i have a image view which is drag able and zoom able but now
I have a view and template called index.html. I have a image which is
Hope someone has an easy answer on this. I have a header image which

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.