android - Vertical-striped background in XML? -


i want set view background regular grid of vertical stripes. stripes alternate between 2 colors. (for example, across single row, there might 6 pixels of light gray followed 2 pixels of dark gray, repeated fill width.)

it's easy enough using bitmap (either resource or generated in code). 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 way strictly xml drawables, without using bitmap resources?

unfortunate, i'm pretty sure answer no.

of 3 tasks required, 2 done without code. can create base of stripes pattern <layer-list> of 2 or more <shape> items. can create repeating tile pattern using <bitmap> xml drawable. trick required middle step: <bitmap> not accept drawable source value (only image) there no way link 2 without intervention of little code create bitmap (like have written).

i love see tile modes applied more drawables well, , +1 giving me sample of creating pattern in code :)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -