TAGS :Viewed: 9 - Published at: a few seconds ago

[ Draw a shape like this in android ]

I want to draw a shape like this in xml and use it as background of a Linear Layout enter image description here

how can i draw something like this in android xml ?

thanks

Answer 1


I would suggest you have this as PNG in ImageView as background, otherwise, you have to extend some simple view and override the onDraw part as a shape:

http://developer.android.com/training/graphics/opengl/draw.html

Answer 2


You can use a LayeredDrawable with 4 ShapeDrawable layers. A green rectangle which fills the bounding area and 3 white rectangles to overlay the green rectangles and create the desired shape. The white rectangles can hang over the edge. Please note that this is only one approach you could draw one white rectangle and several green rectangles too.

If there was not a requirement to use xml based Drawable classes you could create your own Drawable sub class.