I would like to include a bottom right triangle on the background of each item in a listview.
I can achieve this using nine-patch images:
But, there can be different possible colors, so I would like to do this with XML drawables, so that I can easily add more colors.
My questions are 2:
1) How I can draw triangles as XML drawables? (I have realized that the triangle is not one of the possible drawing shapes in Android)
2) In case I manage to achieve a triangle drawable, how can I force that drawable to say at the bottom right background? (with nine-patch images is pretty easy, but I don't know how to do the same with drawables)
1) If there is no need for scaling then you could simply take your ninepatch drawable and recolor it. For example if your base triangle had transparent background and the triangle was white you could do something like this to color it into red:
NinePatch ninePatch;
NinePatchDrawable drawable = new NinePatchDrawable(ninePatch);
drawable.setColorFilter(Color.RED, Mode.MULTIPLY);
2) Solved since you know how to do it with ninepatches
Related
How to make shape like on image?
Bottom left and right corners is simple. But top left and right corners...
radius="-10dp" won't work
For more complex shapes such as the one you are looking for you are better off using either vector or PNG resources than shape drawables.
Shape drawables are great for very simple shapes, but don't support a full suite of drawing options.
Like the image on the right,
I want to treat multiple separated shapes as 1 shape in the color gradient behavior!
Any Ideas?!
That is like four separate squares, so no compound shapes? In any case ShapeDrawable, those SVG-like XML vector drawing tools, with clips at the end.
As It was suggested in one of my questions I have to use 9-patch image with gradient for listview item background.
But when I use 9-patch image, there are still problems with gradients:
9-patch, test.9.png:
But when I left transperent line 1 px height between gradient and bottom 9-patch line, that responds for horizontal content placement it's all ok, and I have good looking gradients.
9-patch image:
And closer to see transperent line:
And it's a result:
I've got good looking gradients, but there are transparent lines, that I don't need. On the image you can see black background behind list because of this line. How to draw 9-patch image in order to have good gradients and don't have "holes" in background?
I'm using actionbarsherlock for fragments.
the Draw9patch images doesn't work well with gradients you will find some diferences displaying it in several Android OS so donĀ“t use it.
Use a GradientDrawable
Changing gradient background colors on Android at runtime
Creating Nine (9) Patch png files with Gradients
In my project i need to create the frames, lines and all the shapes required from the drawable folder. I could draw a rectangle and frame and all from drawable. But the problem comes when i need to create arrows from the drawable folder.
Please help me to draw the up arrow and down arrow as shown in the images in the drawable folder.
You cannot draw complex shapes currently with the builtin tools android has. ShapeDrawable lists all the possibilities you have for now.
Why don't you just create different sizes of the arrow in png (ldpi, mdpi, hdpi), and use those? That is the recommended way.
If you want to do custom things, you either should look into SVG, or draw your own.
hi,
I'm trying to implement something similar to the image attached. I have two textviews one on top of the other and i want their borders to look like the one in the image. I was able to draw rounded corners by setting the cornerradii of the GradientDrawable but i have no clue as in how to draw the slope on the right side of the first textview.
Any help on how to do this is much appreciated!!
thanks.
I would in this case do the graphics in a some graphics editing program (Photshop, GIMP or Inkscape for example). Two different drawings, one for the top part and one for the bottom. Then convert the drawings to NinePatchDrawable to be used as backgrounds for the text views. Since this type of drawable can be made larger or smaller depending on the length of the text in the TextViews.
You can use a transparent background image instead of drawing the background. Else you can use the canvas.
Edit : bad image example :-)