0

I'm a complete newbie to Android. How can I fade in the main activity? Basically after I open the app I want the screen to be black and then fade in an image. I have been trying to do this for the last 2 hours and I can't seem to find a solution.

This is my code:

package com.example.radu.gladiators2;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

/**
 * Created by Radu on 8/8/2016.
*/

public class Splash extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    View decorView = getWindow().getDecorView();
    if (hasFocus) {
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
    }
}

And this is the 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">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/splash_image"
    android:id="@+id/imageView"
    android:scaleType="centerCrop" />

Radu
  • 584
  • 1
  • 6
  • 30
  • here's an example http://stackoverflow.com/questions/18475826/fade-in-animation-on-activity-transition – ono Aug 08 '16 at 21:06
  • I tried to adapt it to my problem but it doesn't seem to work on a main activity. – Radu Aug 09 '16 at 12:08

1 Answers1

0

Try this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutAnimation="@android.R.anim.fade_in" >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/splash_image"
    android:id="@+id/imageView"
    android:scaleType="centerCrop" />
X09
  • 3,827
  • 10
  • 47
  • 92