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>
Related
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!
I'm trying to have a perfectly round shaped button.
I have tried with the below code using shape.
but issue i am facing is that when the view has two text in it, it looks almost a circle but as soon as the view has one and three character in it it looks oval shaped.
shape code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="true">
<corners android:bottomRightRadius="20dip"
android:bottomLeftRadius="20dip"
android:topRightRadius="20dip"
android:topLeftRadius="20dip"
/>
</shape>
Please check the nearly rounded shaped button where number 2 and 22 are written in the picture
I have used the same code for all of the buttons(mentioned above)
In your layout file (or in code), keep the dimensions of the Button fixed (width=height=some dp).
In example:
layout_width="48dp"
layout_height="48dp"
Im trying to achieve a component to make custom shadows to buttons or other components, i know that it will be easier with a 9patch or a png with the shadow, but i want to change it color and size programmatically also in its states (pressed,etc), so i decided to try with 9 images, all in XML so the shadow shades start its gradient from the side of the component.
<!-- Left Shadow layer -->
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="0"
android:endColor="#FFFF0000"
android:startColor="#00FF0000" />
</shape>
</item>
It looks good, the problem is on the corners and with the android:gradientRadius parameter now its set to a fixed size, but in the contextual help is said that can be set in a percentage of the base size 10% or parent size 10%p, what i want its to set a 100%p radius so the gradient will always go from the main color and disappear in the edge of the square.
-- EDIT --
The android doc about gradientRadius gradientRadius
<shape android:shape="rectangle" >
<gradient
android:endColor="#00FF0000"
android:startColor="#FFFF0000"
android:gradientRadius="18"
android:centerX="100%"
android:centerY="100%"
android:type="radial" />
</shape>
And thats where im now :( i do not know how can i set this size to fit its parent view.
Any help will be appreciated, when im finished with the component i will put the code in an answer :) so typical buttons can have customizable shadows in xml.
An image of the deserved component.
--Edit--
Im still interested in this :) no one has a clue?
I think you should give up with xml and implement drawable in code.
When you extend Drawable class you can get size as rectangle with getBounds(). Also you can dynamicaly recalculate in onBoundsChange method.
You can also easily construct gradients and use them in Paint object (setShader method)
In the image below is the effect I want(notice the subtle green at the bottom of the screen). I also want to use it as multiple screens so I want it to be the background. Is there any way to achieve this?
Set the png as background, or create a shape in xml:
Create an xml file - let's call it "gradient_background.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#ff0000ff"
android:endColor="#00ffffff"/>
<corners android:radius="10dp" />
</shape>
Change the hex color values to the ones you want.
and add it as background to your ViewGroup e.g. LinearLayout:
android:background="#drawable/gradient_background"
EDIT:
To achieve what you mentioned in your comment, that the gradient height should stay fixed while positioned at the bottom, but the white area can stretch vertically, I suggest you use a nine-patch which you can create with the Draw Nine Patch Tool. Launch the tool from your SDK's tools folder - click the nine-patch bat file (and wait a while for it to launch, then import your png). You then draw black lines along the sides of your image to define which parts can be stretched, name the file something.9.png and reference it as background in your ViewGroup. Please see the linked-to documentation for details.
I want to create a button background (or button itself) that look exactly like the below one.
I'm doing it currently with an image. I tried to create a similar one using the following XML, but it doesn't look as expected.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#f0600000"/>
<stroke
android:width="10dp"
android:color="#FFFF6666"/>
</shape>
Actually I want a round button with 3 pixel shadow and 1/4 width stroke in red color around the white circle. I have not succeeded with the shadow part at all. Thanks for any sort of help.
Well, the solid fills the middle and stroke paints the border. Since you want 3 colors you will have to use 2 drawables, painting white circle over the red circle with grey border. You can then use LayerDrawable to keep these as one unit