Reputation: 301
I have three images that depicts the company logo, name and slogan. I want to animate these three images in such a way that a logo appears first, then the name and then the slogan. After these three animations, I want the screen to disappear and display a new activity. How to do this? Please help me.
Upvotes: 1
Views: 4187
Reputation: 24181
add a listener your first animation , and in the method : onAnimationEnd()
, then launch your second animation of the second image , and so on
Example :
NOTE : initialise your img2 and img3 visibility to GONE
public class YourActivity extends Activity implements AnimationListener{
......
@Override
public void onCreate( Bundle savedInstanceState){
super.onCreate(savedInstanceState);
....
ScaleAnimation a1 , a2 , a3;
//define your animations
a1 = new ScaleAnimation(0.0f,1.0f);
a2 = new ScaleAnimation(0.0f,1.0f);
a3 = new ScaleAnimation(0.0f,1.0f);
// duration and behavior of ur animations
a1.setFillAfter(true);
a1.setDuration(1000);
a2.setFillAfter(true);
a2.setDuration(1000);
a3.setFillAfter(true);
a3.setDuration(1000);
a1.setAnimationListener(this);
a2.setAnimationListener(this);
a3.setAnimationListener(this);
img1.startAnimation(a1);
}
Override
public void onAnimationEnd(Animation a){
if(a == a1 ){
img2.setVisibility(View.VISIBLE);
img2.startAnimation(a2);
}
if(a == a2){
img3.setVisibility(View.VISIBLE);
img3.startAnimation(a3);
}
if(a == a3){
startActivity(new Intent(YourActivity.this , SecondActivity.class);
}
}
}
Upvotes: 1
Reputation: 40203
There are a couple of ways to achieve this, you can read about them here
Hope this helps!
Upvotes: 0
Reputation: 800
If I understand you correctly you're going to have these three images on the same screen and then displaying each image after a certain amount of time.
As long as you aren't going to do anything while the splashscreen is showing and the time between images is less than five seconds, you don't have to use another thread.
So, the easiest way would be to set an image, sleep for say a second, then show the next image. Use a boolean so you won't show the splashscreen twice incase the user presses the back button before you were able to handle a back button press.
if(!showedSplash)
{
logoImageView.setImageDrawable(R.id.drawable.company_logo);
Thread.sleep(1000); // sleep for a second (1000 ms)
nameImageView.setImageDrawable(R.id.drawable.company_name);
Thread.sleep(1000);
sloganImageView.setImageDrawable(R.id.drawable.company_slogan);
Thread.sleep(10000);
showedSplash = true;'
}
Now to change to the next activity
Intent i = new Intent(this,activity2.class);
startActivity(i);
Don't forget to put the activity in the manifest!
<activity android:name=".activity2" android:label="@string/activity2_name"/>
Upvotes: 1