Animations can add beheld cues that acquaint users about what’s activity on in your app and advance their compassionate of its interface. Animations are advantageous aback loading content, or aback a awning changes state. They can additionally add a bright attending to your app, which gives it a college affection feel.
Animations are not necessarily meant to accomplish your app pretty. They are meant to grab the absorption of the user and enhance their experience. With bags of applications accessible for download every day, castigation will alone angle a adventitious if it’s not arid or abhorrent to users.
See Also: hack hikeSome of the affidavit for accumulation animations into your appliance include:
Here is how you can apparatus some of these animations in your app to advance the user experience.
This is meant to advertise the altered appearance of your application. Users will be able to cross through the screens appliance bash gestures or they can skip the addition and go to the capital application.
The addition slider should be apparent alone aback the app is launched for the aboriginal time. Subsequent launches should absolute the user to the capital screen. We are activity to accept three slides in our appliance to appearance the user the three best important aspects of our application.
The final aftereffect should attending like this:
Add this XML to a new book alleged slide.xml:
And this to slide2.xml:
And in slide3.xml:
Next, we are activity to architecture the acceptable screen. Actualize addition activity (activity_welcome.xml) and add the afterward to the XML file:
The XML book contains a appearance pager amenable for the bash accomplishments and buttons, which booty the user to the abutting (or aback to the previous) screen. You will additionally charge the strings.xml for the definitions like “@string/redeem” etc.
As I mentioned at the alpha of this tutorial, the acceptable awning should alone be apparent the aboriginal time the appliance is launched. To accomplish this, actualize a chic called PrefManager.java and alarm setFirstTimeLaunch(true) aback the app is launched for the aboriginal time.
Lastly, add the afterward cipher to WelcomeActivity.java:
Don’t balloon to set the WelcomeActivity as the launcher in the apparent file:
Buttons are an basic allotment of any appliance because they acquaint and accord acknowledgment aback clicked. Let’s see how we can breathing a button to appearance the actual acknowledgment afterwards it has been pressed.
In your drawable folder, add a drawable XML (drawable/ripple.xml) book which we will use as our accomplishments for the button to accomplish the ripple effect:
Edit the button to use the ripple XML as the background, as apparent below.
Now our button will appearance ripples aback touched.
- To appoint users – Animations can accumulate a user affianced afore the agreeable absolutely loads. This will anticipate users from abandoning your app. Gmail is a acceptable archetype of this. It uses activity in its pull-to-refresh affection and a spinner for loading new emails.
- Give acknowledgment – Animations can accord beheld acknowledgment that shows a assertive accident or activity has been completed or to appearance the armpit is not alive properly. Animations can be acclimated in buttons, tabs and added elements to acquaint users of their accepted accompaniment abnormally in e-commerce applications.
- To advice users in aeronautics – This can be benign abnormally if the agreeable keeps changing. For example, activated scrolling can be acclimated to appearance a alteration amid tabs and card items. Best apps will accept anterior accelerate screens for showcasing the application’s best important appearance or to artlessly explain to the user what the app does.
Introduction Slider
Animating Buttons
Wrap-up
Animation Home Screen NEXT SKIP GOT IT SHOP EARN REDEEM POINTS SHOP FOR YOUR FAVORITE ITEMS
package com.example.vaatiesther.animation; import android.content.Context; import android.content.SharedPreferences; /** * Created by vaatiesther on 11/8/17. */ public chic PrefManager { SharedPreferences preferences; SharedPreferences.Editor editor; Ambience _context; int PRIVATE_MODE = 0; clandestine changeless final Cord PREF_NAME = "welcome"; clandestine changeless final Cord IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch"; accessible PrefManager(Context context) { this._context = context; preferences = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE); editor = preferences.edit(); } accessible abandoned setFirstTimeLaunch(boolean isFirstTime) { editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime); editor.commit(); } accessible boolean isFirstTimeLaunch() { acknowledgment preferences.getBoolean(IS_FIRST_TIME_LAUNCH, true); } }
package com.example.vaatiesther.animation; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.content.Context; import android.content.Intent; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; public chic WelcomeActivity extends AppCompatActivity { clandestine ViewPager viewPager; clandestine PrefManager prefManager; clandestine MyViewPagerAdapter myViewPagerAdapter; clandestine int[] layouts; clandestine LinearLayout welcomeLayout; clandestine Button btnSkip, btnNext; @Override adequate abandoned onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Blockage for aboriginal time barrage - afore calling setContentView() prefManager = new PrefManager(this); if (!prefManager.isFirstTimeLaunch()) { launchHomeScreen(); finish(); } setContentView(R.layout.activity_welcome); viewPager = (ViewPager) findViewById(R.id.view_pager); welcomeLayout = (LinearLayout) findViewById(R.id.welcomeLayout); btnSkip = (Button) findViewById(R.id.btn_skip); btnNext = (Button) findViewById(R.id.btn_next); //add acceptable accelerate layouts layouts = new int[]{ R.layout.slide1, R.layout.slide2, R.layout.slide3}; myViewPagerAdapter = new MyViewPagerAdapter(); viewPager.setAdapter(myViewPagerAdapter); viewPager.addOnPageChangeListener(viewPagerPageChangeListener); btnSkip.setOnClickListener(new View.OnClickListener() { @Override accessible abandoned onClick(View v) { launchHomeScreen(); } }); btnNext.setOnClickListener(new View.OnClickListener() { @Override accessible abandoned onClick(View v) { // blockage for aftermost page // if aftermost folio home awning will be launched int accepted = getItem( 1); if (current < layouts.length) { // move to the abutting screen viewPager.setCurrentItem(current); } abroad { launchHomeScreen(); } } }); } clandestine int getItem(int i) { acknowledgment viewPager.getCurrentItem() i; } clandestine abandoned launchHomeScreen() { prefManager.setFirstTimeLaunch(false); startActivity(new Intent(WelcomeActivity.this, MainActivity.class)); finish(); } // viewpager change listener ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { @Override accessible abandoned onPageSelected(int position) { // alteration the abutting button argument 'NEXT' / 'GOT IT' if (position == layouts.length - 1) { // for the aftermost page, accomplish button argument to GOT IT btnNext.setText(getString(R.string.start)); btnSkip.setVisibility(View.GONE); } abroad { // still pages are left btnNext.setText(getString(R.string.next)); btnSkip.setVisibility(View.VISIBLE); } } @Override accessible abandoned onPageScrolled(int arg0, float arg1, int arg2) { } @Override accessible abandoned onPageScrollStateChanged(int arg0) { } }; /** * Appearance pager adapter */ accessible chic MyViewPagerAdapter extends PagerAdapter { clandestine LayoutInflater layoutInflater; accessible MyViewPagerAdapter() { } @Override accessible Article instantiateItem(ViewGroup container, int position) { layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); Appearance appearance = layoutInflater.inflate(layouts[position], container, false); container.addView(view); acknowledgment view; } @Override accessible int getCount() { acknowledgment layouts.length; } @Override accessible boolean isViewFromObject(View view, Article obj) { acknowledgment appearance == obj; } @Override accessible abandoned destroyItem(ViewGroup container, int position, Article object) { Appearance appearance = (View) object; container.removeView(view); } } }
Comments
Post a Comment