I need to make such animated splash screen. Can you help me?
One way is to use Tween Animation like the following. In your case needs more than one anim file
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);
Say like if you have to animate white circle image then do the following
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
image.startAnimation(animation1);
Now you need to create anim file in res/anim/move.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
This is an example. You need to find ways to modify these basic animations for your requirement . For more refer this link
To use a gif for your splash screen.
In your build.gradle file:
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
In your activities layout:
<pl.droidsonroids.gif.GifImageView
android:id="#+id/gifView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/gif"
/>
And finally in your class file:
private static int SPLASH_TIME_OUT = 1500;
private boolean isInFront;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_gif);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// This method will be executed once the timer is over
if(isInFront)
{
// Start your app main activity
Intent i = new Intent(SplashScreen_Gif.this, MainMenuActivity.class);
startActivity(i);
}
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
You can use a gif image like this and use it on your splash screen instead of a normal jpg or png image
Related
In a RelativeLayout I have a TextView and a Button under the TextView and an ImageView covering both of the other objects. As the user opens the activity, the ImageView should cover the other items.
As the user swipes on the image (left or right), it should dismiss so the user can operate the button and read the textfield.
Whith an onClick listener I could dismiss the Image when clicked but I would like an animation, exactly like in a RecicleView when swiping to delete an element.
You could add the desired animation to the onClick event.
1) create(or add if existing) the anim folder inside the res directory and put slide_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
2) Add this code to the onclick action of the image view :
// Refer the ImageView like this
imageView = (ImageView) findViewById(R.id.imageView);
// Load the animation like this
animSlide = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_animation);
// Start the animation like this
imageView.startAnimation(animSlide);
You can modify the animation specs in the xml so you can get the desired effect.
And then just implement AnimatorListener so you can dismiss the image view at animation end.
animSlide.setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//remove image view from the layout
}
});
I have a simple .xml layout file that has a simple ImageView, that I want to switch images on. I decided to go ahead and do it with FrameAnimations, using the AnimationDrawable API.
I have managed to create my animation file in "drawable/file.xml", here is the code:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/image_010_1" android:duration="1000" />
<item android:drawable="#drawable/image_010_2" android:duration="1000" />
</animation-list>
Now, Here is the code that should start my animation:
Image1.setBackgroundResource(R.drawable.image_010);
AnimationDrawable animation = (AnimationDrawable) Image1.getBackground();
animation.start();
For some reason, When i run the app I just see the first frame, and the next image does not come after 1000 milis, or at all! What am I doing wrong? Thanks!
so I managed to solve this problem by adding a Runnable to my ImageView:
image.post(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
animation.start();
}
});
I wanna translate 2 images image When I click on Button, At that time from left image move left to right and right image move right to left(both image come in center at that time stop animation) on emulator using android animation.I'm new to android animation.How could i do that.?
coding is much appreciated.Thanks..
i can't explain everything here but i help you to do that. first you must create two new XML file (Animation in old versions or Tween Animation in new versions) for each image , then use translate. for example:
<translate android:fromXDelta="10"
android:toXDelta="100"
android:duration="2000"
/>
for left image, and for right one use your numbers.
then in java file, set your Button and images. then define animation and use them. i think this example is comprehensible:
final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
final ImageView iv2 = (ImageView) findViewById(R.id.imageView2);
final Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Animation anim = AnimationUtils.loadAnimation(main.this, R.anim.animation);
iv1.startAnimation(anim);
iv2.startAnimation(anim);
}
});
in this example, i use one animation for both of them.
and remember in this site, you can get help from other, not absolute code.
add two xml files to res/anim folder of your project like below:
lefttoright.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate android:fromXDelta="-600%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%" android:duration="300"
android:zAdjustment="bottom">
</translate>
righttoleft.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate android:fromXDelta="0%" android:toXDelta="400%"
android:fromYDelta="0%" android:toYDelta="0%" android:duration="300"
android:zAdjustment="bottom">
</translate>
In your layout file keep one ImageView at the left of the screen and other one at the right of the screen
Use the following code snippet in your button's onClick event:
lefttoright = AnimationUtils.loadAnimation(context,
R.anim.lefttoright);
righttoleft = AnimationUtils.loadAnimation(context,
R.anim.righttoleft);
imageView1.startAnimation(lefttoright);
imageView2.startAnimation(righttoleft);
then implement your animation listener:
lefttoright.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
//update imageView's position (e.g. center)
}
});
Do same thing for righttoleft.
Hope it helps.
I'm working on my first Android project, and I'm starting off by making a simple splash screen that fades to black before the main menu is revealed. So far it works. The problem is right after the image fades out, it pops back up for a split second before showing the main menu.
Here's the code for SplashActivity.java:
public class SplashActivity extends Activity
{
LinearLayout mLinearLayout;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mLinearLayout = new LinearLayout(this);
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.splash);
mLinearLayout.addView(i);
setContentView(mLinearLayout);
Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_out);
i.startAnimation(fade);
fade.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation)
{
startActivity(new Intent(SplashActivity.this, MenuActivity.class));
SplashActivity.this.finish();
}
public void onAnimationRepeat(Animation arg0) {
}
public void onAnimationStart(Animation arg0) {
}
});
}
}
Here's the code for splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "#000">
</LinearLayout>
Finally, here's the xml for fading out:
<set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"
android:startOffset="2500">
</alpha>
</set>
A couple notes:
Right now the splash screen is just for show (meaning I'm aware that right now it's not serving any real purpose).
I can paste the AndroidManifest xml or whatever else you think might be necessary.
Any and all help is appreciated. Thanks!
The animation ends, then it flips back to what it was previously. Android animation is confusing, but imagine what you're seeing is a mirage. Nothing about the view you're animating actually changes. Once its over, it goes right back to what it was.
As an example, create a button 100dp x 100dp, and animate is by scaling is small, or rotating. Very slowly. As its running, if you click on areas that look blank, the button will still register the hit. That's because its still "there", but you don't see it.
What you need to do is set visibility on the image in the animation listener:
public void onAnimationEnd(Animation animation)
{
startActivity(new Intent(SplashActivity.this, MenuActivity.class));
SplashActivity.this.finish();
i.setVisibility(View.INVISIBLE);
}
You may need to do it in onAnimationStart. Experiment.
I did a presentation on this a while back. May be useful:
https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7
This would help.
public void onAnimationEnd(Animation animation)
{
i.setVisibility(View.INVISIBLE);
startActivity(new Intent(SplashActivity.this, MenuActivity.class));
SplashActivity.this.finish();
}
In my android project I have an image that i want to rotate it and create animation for long time.
I can run program and it works fine. but I don't know how can I stop it. if you know please tell me.
Thanks
This is my code, I have a menu with two items, When I click on Start item, startAnimation function runs and when I click on Stop item, stopAnimation runs.:
public class Hypnagogic extends Activity
{
ImageView imView;
Animation an;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView = (ImageView)findViewById(R.id.imView);
}
private void startAnimation()
{
an = AnimationUtils.loadAnimation(this, R.anim.spin);
imView.startAnimation(an);
}
private void stopAnimation()
{
;//there is no any stop function!
}
}
also, in res/anim I put spin.xml that is my animation
<?xml version="1.0" encoding="utf-8"?>
<set>
<rotate
android:fromDegrees="0"
android:toDegrees="-18000"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50000" />
</set>
EDIT: I see. Okay, try the clearAnimation() method associated with the View class. You can call it directly on your ImageView, I'm almost certain this should work for your case:
imView.clearAnimation();
What have you tried? AnimationDrawable has a stop() method. You need to post how you're creating/starting the animation.