Tuesday, 5 November 2013

Switching Android Activities : Fade Out - Fade In Animation

In this post, I will show you how to implement a basic slide-out-slide-in transition animation when switching between Activities in an Android application.

Animation in Android can be implemented either in Java code or XML markup. In this post we will use the latter approach. A similar post will be published on implementing animations in Java code.

We are going to make some assumptions. We will assume that we have 2 activity classes, ActivityA and ActivityB. Now when a button is clicked on ActivityA, we want it to slide out and ActivityB will slide in.

To define the animations in xml, create a file call fade_in.xml in the anim directory found in the res folder and paste the following code.

NOTE : The filename could be any valid android resource name

CODE FOR slide_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="500" />
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="100" android:startOffset="200" />


Create another file called fade_out.xml in the anim directory found in the res folder of your project and paste in the following code. Again, the name of this file could be any valid android resource name.

CODE FOR slide_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="500" />
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="100" android:startOffset="200" />


<translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="500" />

The above code means the X position of the sliding Activity should change from -100 to 0 in 500 milliseconds.

<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="100" android:startOffset="200" />
The above code changes the transparency of the sliding Activity from 1 to 0.

To show ActivityB following an event in ActivityA and apply the defined animations use the following code

startActivity(new Intent(ActivityA.this,ActivityB.class));
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

If you don't understand anything just write it in a comment and get it answered.

Saturday, 2 November 2013

Africa Reborn

Many Africans want to be the Bill Gate or Zuckerberg or Steve Jobs etc of Africa. How about someone in America wanting to be the next Kofi Mensah or Araba Atta or the next you of America. Why habour such small dreams in our empty big heads. We proudly walk in town making noise about degrees. Degrees we earned cheaply by sitting in classes with equally empty headed brothers. Degrees we earned by cramming books into our heads without any practical experiences. Degrees in universities where a 4th year physics student can't even identify a common resistor or diode.
Even without working hard, we have accepted defeat. We never want the truth to be spoken and when someone does, we call him arrogant and braggy. We can't even distinguish between confidence and arrogance. Worst of it all, we proudly call them "too known". What on earth is the word "too known" supposed to mean. From childhood we are taught not to fight for what's right. We shun teamwork and welcome the I want it all attitude. This is what is killing us. Corruption all over. Someone is willing to gimme some money I haven't worked for and he sees nothing wrong with it. I will put his sorry ass in jail soon. I stand for seriousness and reality. I dont live in a utopian world where all is fantastic. I believe in the ups and downs in life. This is what many are trying to skip.
You think because you have a crappy degree you should drive that limousine and live in a mansion? The world has changed and so should you. The wealth of this world is no more for academicians. Its for problem solvers.
Renew your mind and have a better life. Dont let people's thought about you affect your thought process. Be bold and live by faith and action. Life is never a war. Everything in life will be a struggle to you if you see it as a war. Let's get real oo dear Africans. Its a blessing to be black. I see a serious Africa rising and the noise making Africa sinking. Where will you be during this revolution. If you do well, we will praise you. Godwin Amefia, congrats! Keep going and never be a noise maker. Rasheeda Yehuza keep championing your course. The journey is the reward.
Yes, am a HATER, hater of CRAP.