I want to make GradientDrawable for background like the image below.
Linear Gradient with same color in the top and bottom.
I made gradient drawable with start, center and end colors but couldn't set the size of center color.
I also tried <Layer-list> with 2 gradient shape-s but one overlays over the other and either I have gradient on the top or on the bottom.
Can anyone help me ?
use "rect" type ShapeDrawable and ShapeDrawable.ShaderFactory
when implementing ShapeDrawable.ShaderFactory return the LinearGradient using colors array with 4 colors (f.ex: white, dark_blue, dark_blue, white) and positions array with 4 positions (f.ex: 0, 0.2, 0.8, 1)
Related
I'm creating a XML file to use as the custom info windows for markers in the google maps.
I'm struggling to achieve the round corner. I found different solutions. Or use a CardView, or create a background using shapes and give it round corners and use it as background for my layout and so on. But every solution I found, gives you only a single color per background.
My layout has split in two. The top half, the title and bottom half for more specific information and I want to give them two different background color.
If I use a CardView or shape, I can't give them a different background color. If I set a background color for specific elements, the background color stays over the round corner layout and a rectangular-no-round-corner, cover the round corner.
How can I manage this? any ideas?
You might consider doing this programmatically if the requirement is highly dynamic. You can use an ImageView, CardView or whatever you may like and set the background shape and color programmatically wherever necessary like the following.
public static GradientDrawable drawCircle(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.OVAL);
shape.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(10, borderColor);
return shape;
}
Now set the background in your view (i.e. an ImageView) like the following.
imageView.setBackground(drawCircle(getResources().getColor(android.R.color.holo_blue_dark), getResources().getColor(android.R.color.holo_red_dark)));
This is a gradient rectangle with rounded corners. The corner radious is 5dp and gray turns to completely transparent within 20dp.
How would I make this bitmap programmatically?
( It's important to have the corners do the same gradient color transition circularly. So I cannot use one rectangle gradient overlapping with an oval gradient coz this would create a darker area where the two gradients would overlap )
I'm wondering if that's possible to create an effect as shown at the picture below using only 1 Layout. The "Description" is a separate TextView and not related to the question. So basically I need a rect shape with:
Glowing border (stroke and shadow..?)
Middle rectangle with gradient
Outer rectangle
Any ideas if this could be achieved using only one Layout and XML shape as background?
I'm looking to try and implement this widget design. The one thing I'm struggling with is creating that circular dropshadow around transparency. Any suggestions?
One solution for circles: Use a radial gradient with an array of colors and change points. You can set it so from the center to 90% out the radial gradient is transparent, then from 90% to 100% you fade from transparent to black. Something like [transparent, transparent, black, transparent] and [0, 0.9, 0.9, 1.0]
I have some text in a relative layout.I know that we can draw a border with curves using stroke and corner in a separate xml.
Is there a way to apply gradient effect for the border constructed with the stroke? or is there any other way to draw a gradient border?
Thanks in advance.
I don't know of a way to do that trivially, but it seems like you could define two shape drawables and combine with a layer drawable. The bottom one would be a rounded corner rectangle with a gradient, the top one would be a slightly smaller rounded corner rectangle of whatever you wanted the interior color to be. The effect should be something like a stroke gradient, although I haven't tried it.