How to get statup home screen like Linked_in mobile app? - android

I tried in so many ways to get start up screen while opening the app but unable to get as like Linked-in android mobile app home screen.Here i need to show one part of big image in first slide then after 2 seconds it automatically moves right to left and shows second part that image with text and click-able button. How to achieve it please help me.
Here is the linked in mobile app link: https://play.google.com/store/apps/details?id=com.linkedin.android&hl=en
I tried this but not getting as exactly i want
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
//display the logo during 2 seconds,
new CountDownTimer(2*1000,1000){
#Override
public void onTick(long millisUntilFinished){}
#Override
public void onFinish(){
//set the new Content of your activity
YourActivity.this.setContentView(R.layout.second);
}
}.start();
}

As per my understanding you require splash screen ..
Splash.java
---------------
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
Thread logoTimer = new Thread() {
public void run() {
try {
int logoTimer = 0;
while (logoTimer < 3000) {
sleep(100);
logoTimer = logoTimer + 100;
}
Intent intent = new Intent(Splash.this, NewClassToOpen.class);
startActivity(intent);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
finish();
}
}
};
logoTimer.start();
}
}
activity_splash.xml
-------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#drawable/splash"
>
</LinearLayout>
#drawable/splash --- > Place image to drawable folders with name "splash / or as you need"
This is for left to right animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
This is for right to left animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
Enjoy .. Cheers !

Related

How to add animation before the opening of a new activity?

I would like to add an animation before the opening of a new Android Empty Activity. Something like a chroma-keyed video played on top of the current activity and at the end of it, the secondary activity opens up.
You create a splash activity that includes your animation, and you implement an AnimationListener. Inside the method onAnimationEnd() you create the intent that takes you to the second activity. Don't forget to set the splash activity as the Launcher activity on your manifest.
animationObject.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent (SplashActivity.this, MainActivity.class);
startActivity(intent); }
#Override
public void onAnimationRepeat(Animation animation) {
}
});
EDIT: if you want to play a video with media player instead you use a playback listener and run the same intent from onCompletion()
After your startActivity method use the overridePendingTranistion and put the animations in it
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(ActivityA.this, ActivityB.class));
overridePendingTransition(R.anim.enter, R.anim.exit);
}
});
The xml animations are as follows
enter.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
exit.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"
android:toYDelta="0%" />
</set>

Fade in function not working in Eclipse

I have set up the fade in functionality properly but its not working
MainActivity.java
setContentView(R.layout.activity_main);
ImageView iv = (ImageView) findViewById(R.id.sname);
final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
iv.startAnimation(animationFadeIn);
Thread timer = new Thread(){
public void run(){
try{
sleep(4000);
}catch(InterruptedException e)
{
e.printStackTrace();
}finally{
Intent in = new Intent(getApplicationContext(),HomescreenJ.class);
startActivity(in);
}
}
};
timer.start();
fadein.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
Kindly its basically my splash screen. On which i want one image to be stationary and other one to be displayed with Fade-in effect.

What is the best way to implement fade-in and fade-out animations on Android?

I have a few controls that I don't want the user to see all the time, so they need to:
Fade out 5 seconds after activity is created
Fade in when user taps the screen
Fade out after 5 seconds of visibility or when user taps screen again (whichever comes first)
I've seen a lot of implementations of animations out there (including Thread, Handler, and Animation). Which method would work best in this situation?
Here I included the code which i had done in my project. Please check this out. It may help you.
Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
Animation animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
handler = new Handle(this);
animator = new Thread() {
public void run() {
try {
handler.sendMessage(handler.obtainMessage(1));
sleep(2000);
handler.sendMessage(handler.obtainMessage(2));
sleep(2000);
handler.sendMessage(handler.obtainMessage(3));
} catch (Exception e) {
e.printStackTrace();
}
}
};
animator.start();
static class Handle extends Handler {
#Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
if (msg.what == 1) {
iv.startAnimation(animationFadeIn);
} else if (msg.what == 2) {
} else if (msg.what == 3) {
iv.startAnimation(animationFadeOut);
}
super.handleMessage(msg);
}
}
Use following code for fade in and fade out.
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
</set>
happy coding !!

Drawable displayed before tween animation

I have an activity (A) that launches another activity (B) after a calculation. My problem is that when Activity B is launched, an arrow drawable that is supposed to move from left to right while incrementing in size (scaled from .33 to 1) is first displayed for a very short fraction of time before it starts the tween animation. The end result is a bothering flicker of the full size drawable right before it starts animating.
Everything seems to point that the problem is related to the animation file (.xml) and not to the java class. This can be observed when I delete the line arrowImage.startAnimation(arrowExtent); in the following code:
protected void arrowAnimation(Animation arrowExtent) {
// TODO Auto-generated method stub
arrowImage.setImageResource(R.drawable.arrowimage);
arrowImage.startAnimation(arrowExtent);
arrowExtent.setFillAfter(true);
I have tried the following:
Using setImageDrawable instead of setImageResource to the Drawable object.
Setting arrowImage.setFillBefore(false);
Any recommendations will be greatly appreciated.
The animation xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<set android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<scale
android:fromXScale="0.33"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:duration="1000"
android:fillBefore="false" />
<translate
android:fromXDelta="0%"
android:toXDelta="75%p"
android:duration="1000" />
</set>
When activity start you should make ImageView invisible in xml or in onCreate() and when animation starts, you should change it to visible.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// referencing views etc.
arrowImage.setVisibility(View.INVISIBLE);
// or make image invisible in xml
}
protected void arrowAnimation(Animation arrowExtent) {
arrowExtent.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
arrowImage.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) { }
#Override
public void onAnimationEnd(Animation animation) { }
});
arrowImage.setImageResource(R.drawable.arrowimage);
arrowImage.startAnimation(arrowExtent);
}

Animation in android pause the image after animation is done?

I am creating an animation in android for two buttons.Button1 moves from bottom center to center of the screen vertically upwards direction(say in 2 seconds).Once it reaches there,the image should be there for say 2 seconds.Then the second image moves from center_right side of the screen to the center_left side of the screen while the first button is still present.Can some body please tell me how to make the first image be there for some time on the screen.Following is my code :
R.anim.alpha
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="200%p"
android:toYDelta="-11%p"
android:duration="3000"
android:repeatCount="infinite"
/>
</set>
R.anim.anim_card
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="600%"
android:toXDelta="-100%"
android:repeatCount="infinite"
android:duration="4000"
android:fillAfter="true"
/>
</set>
And in Java code:
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
a.reset();
_image.clearAnimation();
_image.startAnimation(a);
Animation b =AnimationUtils.loadAnimation(this, R.anim.anim_card);
b.reset();
btn_card.clearAnimation();
btn_card.startAnimation(b);
You will have to use AnimationListener for that:
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
a.reset();
_image.clearAnimation();
_image.startAnimation(a);
Animation b =AnimationUtils.loadAnimation(this, R.anim.anim_card);
b.reset();
a.setAnimationListener(new 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
btn_card.clearAnimation();
btn_card.startAnimation(b);
}
});
Hope it helps.

Categories

Resources