Next Tutorial
Android AppBar ToolBar Design
Prev Page
View All Tutorials
This is the App Photo - Spinner (with Interpolator Examples)
How To Use Animation Interpolators
Animation Interpolators with Spinner Interpolators are
often used in view animations. They allow you to add additional methods for the action of the animated image, drawable, or text.
When you animate an object it moves in a direct steady style across the view.
However, by adding a selected interpolator to your animation you can add another
way of moving your animation object such as; accelerate, decelerate, bounce, cycle, overshoot, anticipate. These are added to your animation code like this:
android:interpolator="
@android:anim/accelerate_interpolator
By adding this code, the animation object; example, an image, using the Translate method, will
accelerate itself as it moves across the view.
If you added decelerate, then it would slow itself as it moves across the view.
This app will show you the different interpolator methods.
A Spinneris added to present a dropdown type box to the user, who can then select from the items displayed in the box. For this tutorial, a spinner has been used
to allow you to select from the various interpolators method types. When you select one, it will animate for you. This will allow you to see how the different interpolators perform in animations.
For additional reading on View Animations, Interpolators, and Spinners
Interpolators for Animations
Spinners
Material Design Theme
For each template android/gradle/java/xml app you create:
By default;
The res/values-v21 styles.xml file has the code for the material design theme name: Theme Material Light; for devices using android version 5.0, Api 21 or latest.
The res/values styles.xml file has the code for the theme name: Theme Holo Light, which is for devices that are pre material design platforms; ie less than android version 5.0 Api 21.
For this app tutorial, we want to use the
Theme Material
This theme has a dark colored view with a slightly different dark colored action bar. The action bar is at the top of the app view, where you can see the app name.
The code for this is shown in this image.
We need to change the code to read Theme.Material, in our styles.xml file located at res/values-v21 of the app project.
For devices using android 5.0 Api 21, or later versions, they will now see the Theme.Material
For users of devices that are pre or before android 5.0 Api 21, they
will have the Theme.Holo.Light as their theme. We need to change the theme to read Theme.Holo at the res/values/styles.xml file.
Doing so will make users of pre-android 5.0 also see a dark colored theme and action bar.
You can copy paste the code for these themes at the Example Code section on this page, for the styles.xml file
Creating - Naming Your App Using AIDE
When creating your app,(from left menu) choose:
Create New Project;
Then, choose
New Android App(gradle, android Java/xml)
or
Hello World App Java/xml
if your using the original version of AIDE
You can name your app; use;
Spinner
for the App Name and,
for the package name(next line) use:
com.aac.spinnerexample
The Coded Pages
For this app you will use these coded pages:
Layout
1 layout file, main.xml; this page has the code for our Spinner layout; located at res/layout/main.xml, already created, just replace the code on
this page with the code from our Example Code section and save the page.
Java
1 java class page; MainActivity.java; located at app/src/java/MainActivity.java. Already created for you, just copy replace the code from the Example Code
section and save the page.
Imports
Each code class you add has a corresponding
import statement that has to be coded in your apps java file.
The default java page created for our template android app is named MainActivity.java. This is where we put the import codes.
If you were to add additional java class pages to your app, then you would add the 'import statements' for those also.
Each android template app we create has a one page layout (main.xml) and one java class (MainActivity.java) and included by default are the common required 'imports' for us, like:
import android.app;
import android.os;
import android.view.view;
These are the basic required ones; as all apps have one page, one view, and an os.
These are coded at the top of the java class page.
If you add additional pages to your app, but do not add any new code classes, then you don't have to add additional import statements; the default ones are suitable and added when you create the java class page.
Now lets suppose you add additional pages but your only adding text to them.
In this scenario, the system pages created will include the default import statements for you at the java class you create that corresponds to your layout page. No additional import statements are required in this scenario.
Example pages:
Adding text only; no code classes or new widgets
main.xml- MainActivity.java
main1.xml - MainActivity1.java
The default imports are suitable.
Now lets suppose you add another page, and on that page your adding a Frame Animation
main2.xml - MainActivity2.java
At main2.xml layout; your adding an animation layout; including a button and you want it 'clickable' so when clicked it starts your animation.
You would have to add the 'import statements' for the animation java class code and the onClick method at the MainActivity2.java class page; as this page will have the onClick method and Animation method coding.
Imports for This Tutorial
For our 'interpolator app' we must add additional import statements. as this:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
As you look at the java class file, MainActivity.java, you can see all these code methods in the code which is why they must have a corresponding import statement.
You can copy paste the code from the Example Code section to replace the code on the java page now and save the page.
Also Read
Import Statements, Code Class
Strings
1 strings.xml file; This file has the strings that contains the app_name text - Spinner; you can delete the Hello World text string, it is not needed for this app.
Build Gradle, this page has the code for the SDK min and target versions and our support libraries code if we need to add any to our app.
The support libraries code is added at the 'dependencies' section in the build.gradle file, and the SDK versions are added at the 'defaultConfig' section in the
build.gradle file.
Because we are using Material Design theme we do need to include the code, SDK min 14, and target version 21.
This default file has been created for us and coded with SDK min 14, and target version 21; so we don't have to code those.
And, for this app, we don't need to add any support libraries, so we do not need to edit this page.
For this app, the build.gradle file is located at; AppProjects/Spinner/app/
Manifest
The androidmanifest.xml file is where you can code your 'app theme' name, code your 'intent filters', and add other necessary codes if your app requires them.
You can also code your SDK min and target versions here that your app needs; but since they are already coded in the build gradle file they do not need to be coded here.
Summary, SDK - Dependencies
For most apps you build, you will need to have the proper
SDK min and target version coded in either the build.gradle file or the AndroidManifest.xml page. At this time, it is added at Build gradle for the 'template' apps we create.
And, for some apps we develop, we have to add 'support libraries'. To learn about setting your SDK versions, and adding support libraries (dependencies), goto
Tutorial 1 - AndroidManifest and Build Gradle