Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade In Android Launch Activity

Looking for help fading in my launch activity. I've found LOTS of posts about fading between activities that are being launched with intents, but nothing about how to fade in your launch activity. I've tried overridePendingTransition(int animationIn, int animationOut) but that hasn't worked for me. I've placed it in the onCreate(..) method and the onStart(..) method but have been unsuccessful. Any help or direction would be appreciated.

Thanks.

like image 876
raisedandglazed Avatar asked Mar 12 '15 14:03

raisedandglazed


People also ask

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.

What is a fade in Junit?

↳ android.transition.Fade. This transition tracks changes to the visibility of target views in the start and end scenes and fades views in or out when they become visible or non-visible.

How do you show and hide a view with a slide up down animation Android?

In android, we simply hide a view by setting its visibility. We can do this either in programming or in xml. In programming (we can say in Activity, Fragment etc) there is setVisibility(int) method to set or control the visibility of the view.


1 Answers

I've made something up for you, it excludes the action bar though. I've modified the hello world demo a little for a simple example :

  1. Set a translucent theme to your launcher activity, I called it Translucy :

    /res/values/style.xml

    <style name="Theme.Translucy" parent="android:style/Theme.Translucent">
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">@android:color/transparent</item>
    </style>
    

    AndroidManifest.xml :

    <activity
        android:name=".MainActivity"
        android:theme="@style/Theme.Translucy"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
  2. Create an id for your main xml layout, I called it rlayout_main, and set it to invisible :

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
    
        android:id="@+id/rlayout_main"
        android:visibility="invisible"
        android:background="@android:color/holo_blue_dark"
    
        tools:context=".MainActivity">
    
          <TextView
              android:textSize="50sp"
              android:text="@string/hello_world"
              android:layout_centerInParent="true"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
    
    </RelativeLayout>
    
  3. Create an AlphaAnimation and animate your main parent layout :

     public class MainActivity extends Activity {
    
         @Override
         protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
    
         RelativeLayout relativeLayoutMain = (RelativeLayout) findViewById(R.id.rlayout_main);
         AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
         alphaAnimation.setDuration(3000);
         alphaAnimation.setFillAfter(true);
         relativeLayoutMain.startAnimation(alphaAnimation);
         }
     }
    

    (EDIT) : To save a little code you can also use ViewPropertyAnimator to animate your layout instead of creating an AlphaAnimation :

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        RelativeLayout relativeLayoutMain = (RelativeLayout)  findViewById(R.id.rlayout_main);
        relativeLayoutMain.animate().alpha(1).setDuration(3000);
        }
    }
    

Hope this helps, like I said its not perfect because it excludes the ActionBar, but it might be something to start with.

like image 70
A Honey Bustard Avatar answered Oct 02 '22 17:10

A Honey Bustard