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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:17:29+00:00 2026-05-20T06:17:29+00:00

I want to set a View background that is a regular grid of vertical

  • 0

I want to set a View background that is a regular grid of vertical stripes. The stripes alternate between two colors. (For example, across a single row, there might be 6 pixels of light gray followed by 2 pixels of dark gray, repeated to fill the width.)

It’s easy enough to do this using a Bitmap (either as a resource or generated in code). For instance:

ShapeDrawable bg = new ShapeDrawable(new RectShape());
int[] pixels = new int[] { 0xFFCCCCCC, 0xFFCCCCCC, 0xFFCCCCCC,
    0xFFCCCCCC, 0xFFCCCCCC, 0xFFCCCCCC, 0xFF999999, 0xFF999999};
Bitmap bm = Bitmap.createBitmap(pixels, 8, 1, Bitmap.Config.ARGB_8888);
Shader shader = new BitmapShader(bm,
    Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
bg.getPaint().setShader(shader);
view.setBackgroundDrawable(bg);

Is there a way to do this strictly as XML drawables, without using bitmap resources?

  • 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-20T06:17:29+00:00Added an answer on May 20, 2026 at 6:17 am

    Unfortunate, but I’m pretty sure the answer is no.

    Of the three tasks required, only two could be done without any code. You can create the base of the stripes pattern as a <layer-list> of two or more <shape> items. You can also create a repeating tile pattern using a <bitmap> XML drawable. The trick is the required middle step: <bitmap> will not accept another drawable as a source value (only an image) so there is no way to link the two without the intervention of a little code to create a Bitmap (like what you have written).

    I would love to see tile modes applied to more drawables as well, and +1 for giving me a sample of creating the pattern completely in code 🙂

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

Sidebar

Related Questions

I want to set a background of a View with a tiled bitmap, but
I have a view that has a tooltip attribute. I want to set that
In XCode 4.2, I want to set a view's background colour to a particular
I want to set an background to my listview that have different size (depending
I want to set a background image to my listview so that regardless of
I have four tabs that hold four listviews, I want to set a background
I want to set an image as a setting's page's/view's background image. I have
i want set the visibility to itemized overlay in map view. if the zoom
i want to set some content on android text view. Like... What is a
I want to set the width of one particular textbox in my view. No

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.