I am trying to achieve this animation here:
I want to do something similar with a RelativeLayout having a rounded corner background:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="5dp" />
... solid color etc code here ...
</shape>
I am trying to think of ways to animate it. What I have thought of is probably using 4 translation animator to animate in the 4 directions, finding the 4 corners of the RelativeLayout position. The shape of the animation got me thinking a little too. Initially I thought of achieving it with a 1dp height rectangle shape, but it will not have the sort of sharp edges like the animation above. Can i achieve that kind of shape without using an image?
Any help pointing in the right directions as how to achieve this kind of animation will be greatly appreciated!
Related
I'm currently drawing a simple rounded rectangle using an XML drawable (black BG for contrast):
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/white"/>
<corners android:radius="15dp" />
</shape>
What I would like to achieve is adding an inside outline/glow that is a gradient so that it looks like this:
I know it will most likely involve several XML gradient elements in a layer list, but where I get stuck creating this is figuring out how to:
Have the gradient follow the curves in the corners since they are rounded (always face towards the center of the rectangle, or as close as possible)
Avoid the effect having double intensity in the corners like it is in the example. This will happen if 4 gradients are simply overlapped or a radial gradient stretched to a ellipse is used. The density of the outer color needs to be consistent all the way around the rectangle, or as close as possible
It is highly preferable if feasible that the implementation is modifiable so that:
I can control how far into the rectangle the gradient reaches
I can control how quickly the gradient fades at any given distance (control its density/intensity)
I can remove any side from the gradient so that I can have only 1 or 2 edges and their corners glow if needed
This is a perfect example of what I need except that it is obviously much simpler to do with a circle and a radial gradient. I need this consistent pattern but with the rounded rectangle:
Can you help me with a solution for custom color shadow with gradient effect?
I need this effect for ImageView shadow
For example, I try to use gradient like:
<gradient
android:type="radial"
android:startColor="#000000"
android:endColor="#43bababa"
android:gradientRadius="100dp"
android:angle="270"/>
But this gradient has ring effect, not rounded corners.
There's problem in every possible solution:
About shadows:
You can use CardView. It has rounded corners and shadows out of the box. But as I know compat realization doesn't cut corners of inner layouts. It just fits image in it (as result tiny white strokes around image example)
You can use 9 patch image as background. Not so easy to place layout layers correctly
SOLUTION YOU WILL LIKE:
Use CardView with RoundedImageView
Here's what I want to do: Click
I have a progressBar and I want to overlay this onto it so that I can achieve rounded corners. Problem is, if I use a 9patch image, it doesn't scale down, and scaling up pixelates the corners. Also, the corners when I increase the size of the progressBar, don't look sharp enough.
So I thought maybe drawing such a rectangle on top would make it 100% precise with crisp quality. Unfortunately, I've never used that before and there's no tutorial similar to what I want to achieve.
Thanks for all the help.
If you apply a shape drawable, you should be able to achieve what you want. You reference it just like any other drawable (android:src/android:background).
Let's name this file rounded_rect.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="#80ffffff" />
</shape>
The radius can be more or less than 20dp, it will actually scale down if the container that it's drawn in requires less for the sides to be perfectly rounded; the color is white with a bit of transparency (#80).
Save it to your drawable folder and refer to it as you usually would with any png/jpg/etc drawable:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/rounded_rect" />
I want to create a simple animation for my Android Application.
I have a very big Image inside an ImageView (1900 x 1200). This Image has small stripes which are transparent so that the background of the View is visible inside of the transparent stripes.
Basically i now need the background to be one color and i need a small white stripe moving from the top of the screen to the bottom of the screen. That should be repeated infinitly. You can imagine of it like the front light animation of the black car in Knight Rider.
I tried to implement that using another image in the background which i moved like that:
ObjectAnimator repeatAnimation = ObjectAnimator.ofFloat(this.imageViewLightFloatLeft, "y", -Helper.getDisplayHeight(this.getActivity()), Helper.getDisplayHeight(this.getActivity()));
repeatAnimation.setDuration(2000);
repeatAnimation.setRepeatCount(ObjectAnimator.INFINITE);
repeatAnimation.setRepeatMode(ObjectAnimator.RESTART);
repeatAnimation.start();
Unfortunately this is not a good solution because it is lagging really hard. As i mentioned i have an ImageView with a big Image (1900 x 1200) in the front and it is slowing down the animation rapidly.
So i need another solution for what i want to do.
How can i implement my animation?
Using a Gradient as the Background of the View and animate that Gradient does the trick:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#000000"
android:gradientRadius="1000"
android:startColor="#85E9FF"
android:type="radial" />
</shape>
If you create an outset border in CSS the browser varies the border colour for each edge to make the shape appear to protrude from its parent.
Is there an easy way to do this in an android layout or do I need to set each line colour manually?
Update - added example below:
Example http://www.witzelsucht.co.uk/googleplusheader.png
Set the background of an ImageView to a 9 patched drawable resource with the desired shadow/bevel around the edge. Lets say it takes 5 pixels to create the effect you want. Then set the padding of the ImageView to 5 pixels. Then set the bitmap to any image.
ImageView.setBackgroundDrawable
ImageView.setPadding
ImageView.setImageBitmap
Even easier, use a shape with a stroked border and set it as the background of the view:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000" />
<stroke android:width="1px" android:color="#ffffff" /></shape>
I'm not aware of any native support for Views to have borders. Your question reminded me of this question that I was looking at recently:
Is there an easy way to add a border to the top and bottom of an Android View?