<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pradeesh MuthuKumaraSwamy</title>
    <description>The latest articles on Forem by Pradeesh MuthuKumaraSwamy (@pradeeshmp).</description>
    <link>https://forem.com/pradeeshmp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F439889%2Fb74eeded-1633-4d94-af42-ad193800afa0.jpg</url>
      <title>Forem: Pradeesh MuthuKumaraSwamy</title>
      <link>https://forem.com/pradeeshmp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pradeeshmp"/>
    <language>en</language>
    <item>
      <title>Android - Splash Animation Made simple</title>
      <dc:creator>Pradeesh MuthuKumaraSwamy</dc:creator>
      <pubDate>Sun, 16 Aug 2020 16:14:18 +0000</pubDate>
      <link>https://forem.com/pradeeshmp/android-splash-animation-made-simple-3c6l</link>
      <guid>https://forem.com/pradeeshmp/android-splash-animation-made-simple-3c6l</guid>
      <description>&lt;p&gt;Splash screens are like &lt;a href="https://en.wikipedia.org/wiki/Termite"&gt;Termite&lt;/a&gt; insects, it born and die for some moment, so coding some animation over their can bring some charisma.&lt;/p&gt;

&lt;p&gt;Here is how to make an simple animated splash screen using animation xml tags,&lt;/p&gt;

&lt;h1&gt;
  
  
  Splash Layout
&lt;/h1&gt;

&lt;p&gt;Create your splash activity layout and brush up the background with theme based color or drawable.&lt;br&gt;
In this example I used drawable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ePEFcuRO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ev02rpzxdnfmp8n8bqmq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ePEFcuRO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ev02rpzxdnfmp8n8bqmq.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this splash space I use Polestar logo to animate,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-4hg68r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/au6y5om3k9rhtmz7w9yp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-4hg68r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/au6y5om3k9rhtmz7w9yp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I cropped the image into two halves, so that I can give an crossing and joining animation effect of the logo, to crop or edit I prefer  &lt;a href="https://pixlr.com/"&gt;Pixlr&lt;/a&gt; tool, this can reduce the development time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--niVB8EiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ymm9znhxkhfeexrni78c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--niVB8EiZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ymm9znhxkhfeexrni78c.png" alt="ews_splash_logo_01"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--toPuVAtq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wrvj4e1sseom8oy5ul0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--toPuVAtq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wrvj4e1sseom8oy5ul0g.png" alt="ews_splash_logo_02"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Image view component place the images and add some layout corrections(Margins, Gravity, ...) to bring the actual view.&lt;br&gt;
Added to that I used TextView component to show some fade effect of title&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ews_bg"&amp;gt;

    &amp;lt;ImageView
        android:id="@+id/ewsSplashLogoImgRightImgv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|center_vertical"
        android:layout_marginLeft="130dp"
        android:layout_marginBottom="130dp"
        android:src="@drawable/ews_splash_logo_01" /&amp;gt;

    &amp;lt;ImageView
        android:id="@+id/ewsSplashLogoImgLeftImgv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="130dp"
        android:layout_marginTop="130dp"
        android:layout_gravity="center|center_vertical"
        android:src="@drawable/ews_splash_logo_02" /&amp;gt;

&amp;lt;TextView
        android:id="@+id/ewsSplashLogoTitleTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="85sp"
        android:layout_marginTop="380dp"
        android:textColor="@color/colorPoleThemeText"
        android:text="e-WattStat"
        android:layout_gravity="center|center_vertical"
        /&amp;gt;


&amp;lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AlT6ieKe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mzujuwckw84jlmf0hsh3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AlT6ieKe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mzujuwckw84jlmf0hsh3.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Anim Folder
&lt;/h1&gt;

&lt;p&gt;Now create folder named &lt;strong&gt;anim&lt;/strong&gt; under &lt;strong&gt;res&lt;/strong&gt;&lt;br&gt;
Right click on anim folder and create new &lt;strong&gt;Animation Resource File&lt;/strong&gt;&lt;br&gt;
Our example contains three components to animate(Logo1, Logo2, Text), so I created three xml respectively,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qQu3P1w3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0hcz44g69vfn7dwbtgep.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qQu3P1w3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0hcz44g69vfn7dwbtgep.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;frombottomcorner.xml&lt;/code&gt;, used translate tag to move the image from bottom corner of the splash layout&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;set xmlns:android="http://schemas.android.com/apk/res/android"&amp;gt;
    &amp;lt;translate
        android:duration="1200"
        android:fromXDelta="-50%p"
        android:fromYDelta="50%p" /&amp;gt;
&amp;lt;/set&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;android:duration&lt;/code&gt; is the time take to finish its animation.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;fromtopcorner.xml&lt;/code&gt;, same as of previous but changed the delta value to move the image from top corner&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;set xmlns:android="http://schemas.android.com/apk/res/android"&amp;gt;
    &amp;lt;translate
        android:duration="1200"
        android:fromXDelta="-50%p"
        android:fromYDelta="50%p" /&amp;gt;
&amp;lt;/set&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;textfadeout.xml&lt;/code&gt; is slightly different because here we going to animate the text view to fade, so used &lt;code&gt;alpha&lt;/code&gt; tag to perform this job.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"&amp;gt;
    &amp;lt;alpha
        android:duration="3000"
        android:fromAlpha="0.0"
        android:toAlpha="1.0"&amp;gt;&amp;lt;/alpha&amp;gt;
&amp;lt;/set&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;android:fromAlpha&lt;/code&gt; - starting alpha value&lt;br&gt;
&lt;code&gt;android:toAlpha&lt;/code&gt; - final/end alpha value&lt;br&gt;
&lt;code&gt;android:duratio&lt;/code&gt; is the time take to finish its animation&lt;/p&gt;
&lt;h1&gt;
  
  
  Splash Activity
&lt;/h1&gt;

&lt;p&gt;80% of job is done, now just club these animation xml with the view components(ImageView, TextView)&lt;/p&gt;

&lt;p&gt;Here &lt;code&gt;Animaion&lt;/code&gt; class will help to load the animation xmls, and &lt;code&gt;setAnimation&lt;/code&gt; helper method helps to club the xml with respective View component&lt;/p&gt;

&lt;p&gt;Eg, &lt;br&gt;
&lt;code&gt;Animation logoFromLeft = AnimationUtils.loadAnimation(context, R.anim.fromtopcorner);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;logoImageViewLeft.setAnimation(logoFromLeft);&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SplashActivity extends AppCompatActivity {

    ImageView logoImageViewRight;
    ImageView logoImageViewLeft;
    TextView appTitleTextView;

    Animation logoFromRight;
    Animation logoFromLeft;
    Animation appTitleFade;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        logoImageViewLeft = (ImageView) findViewById(R.id.ewsSplashLogoImgLeftImgv);
        logoImageViewRight = (ImageView) findViewById(R.id.ewsSplashLogoImgRightImgv);
        appTitleTextView = (TextView) findViewById(R.id.ewsSplashLogoTitleTv);

        logoFromLeft = AnimationUtils.loadAnimation(this, R.anim.fromtopcorner);
        logoFromRight = AnimationUtils.loadAnimation(this, R.anim.frombottomcorner);
        appTitleFade = AnimationUtils.loadAnimation(this, R.anim.textfadeout);

        logoImageViewLeft.setAnimation(logoFromLeft);
        logoImageViewRight.setAnimation(logoFromRight);
        appTitleTextView.setAnimation(appTitleFade);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
            }
        }, 4000);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Ta-da
&lt;/h1&gt;

&lt;p&gt;Seems everything fine, go for a run&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZL304Fmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3xcmko2acso99kanupwu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZL304Fmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3xcmko2acso99kanupwu.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can refer &lt;a href="https://developer.android.com/guide/topics/resources/animation-resource"&gt;here&lt;/a&gt; to get different set of tags to make the animation even better &lt;/p&gt;

</description>
      <category>android</category>
      <category>design</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
