This Tutorial View Animator with Array
Prev Tutorial Android Card View
Next App Tutorial View Animator with Views
If you are just arriving at this page; and you are not familiar with with creating Android Apps, we suggest you begin with our tutorials:
Coding Android App Pages
and How To Create a Simple App in Android
From there follow along with each tutorial lesson.
AIDE and ANDROID STUDIO
We are using AIDE(a mobile coding environment using language java/xml), to create these tutorial apps on our
tablet(7" screen) that has android version 5.0.
Once we build and RUN our app; we then install the app on this same tablet; and the app is also installed on a smart phone that has android version 6.
AIDE can be installed on any android version from 4 - 8.
We are using the AIDE coding editor to code our pages; and then to Create - RUN our apps. AIDE is a SDK coding environment for android devices like a tablet or smartphone.
AIDE has a free and paid version.
Once you create your apps code pages, you need to RUN the app to build your apk package; then you INSTALL it on your tablet or smartphone.
For info on using AIDE, gohere
can also create; RUN your apps using the code in these tutorials, with Android Studio. Android Studio is for desktop computers. Choose Java XML as the programming language.
Android Studio is free to install and use for your android app development. Although not as convenient as testing your app on an actual android device; you can test
your newly created app in Android Studio using its' android emulator.
Complete Example Codes are available for each of our tutorials. With these example codes you can make a functioning android app in
either AIDE or Android Studio.
First, create a java/xml android template app using AIDE, (or Android Studio). Then you can get the code for this app from the EXAMPLE CODE section on this page.
Replace the code on the pages you need to(with our tutorial code); in order to create this app.
Sometimes, new pages have to be created.
All the other coded pages in your app
can remain as they are; they don't need to be changed.
This is the App Photo - View Animator
Where - How - Why To Use View Animator
is a coding class introduced in android version 1.0, api 1. It is a code class for animating views. You can use the view animator to animate individual photos
just one view; or you can animate a selection of views. Each view can have text, photos, buttons, whatever you want to add to it.
To animate using two or more views, you can add each view to your layout file and then animate the different views. To animate a selection of photos by using
just one view in your layout, you need to add an array containing your photos to the java class file, MainActivity.java.
For this app tutorial, we are coding a view animator using the array method. You can add as many photos as you want to the array. We also added a Next button
that when clicked will browse the photos using the View Animator's animation out/in method; much like a slideshow.
The images we are using are about 300x200px size. We added six images and one of the images is added using a layerlist . This allowed us to add a border background to
the image. The layerlist xml file(acatlayer.xml) and layerlist image (afiestycat.png) are added to the drawable folder of your app project as are the other five png images.
We implemented the Material Design dark theme for our app theme. Because we are using a android/java/xml template app to create our app tutorials, the Material Theme Light
app theme is added for us automatically in the styles.xml at res/value-v21 folder of our app project.
Because we want to change the theme color to the darker theme, we simply
need to change the theme name in the styles.xml file from Theme.Material.Light to Theme.Material. You can copy paste the code for this from the Example Code section on this
Additional Reading at Android Developer Website:
Creating - Naming Your App Using AIDE
When creating your app,(from left menu) choose:
Create New Project;
New Android App(gradle, android Java/xml)
Hello World App Java/xml
if your using the original version of AIDE
You can name your app whatever you like; if your using the name as shown in our example code use;
for the App Name and,
for the package name(next line) use:
The Coded Pages
For this app you will use these coded pages:
1 layout file, main.xml; this page has the code for our View Animator 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.
For this layout we added our LinearLayout container, then added the required ViewAnimator element, and included a Button so we can click to browse the photos.
at the drawable folder we add all the images we are using for this app, and also our shape drawable xml file, and the layerlist xml file.
These are coded as a xml file because they are drawables; any shape drawables or layerlist you create have to be added to the drawable
folder in our app project along
with any images you have coded(added) to the layerlist. For this app, our layerlist, acatlayer.xml, has one png included 'afiestycat.png, which we added to our drawable folder.
To create our layerlist, first we make a shape drawable xml file; named aphotosquare1.xml, which is the square shape background for our image with the color white.
Next we create our layerlist xml file named 'acatlayer.xml', and to that page we add our aphotosquare.xml shape code; and the fiestycat image code.
Now we have our
layerlist coded named 'acatlayer.xml' In your MainActivity.java page, at the image array code, where you add the photo names, you add the layerlist file name, just like adding a
photo. So code it as 'acatlayer' Looking at these images you can see how the xml files are coded.
Because we want to add a border around the fiestycat image we code our
shape drawable width and height so it is larger than the fiestycat image width and height.
This is the code for the Shape drawable - aphotosquare1.xml
This is the code for the layerList - acatlayer.xml
1 java class page; MainActivity.java; located at app/src/java/MainActivity.java, already created; we need to edit the code in this page for our View animator. Just copy
and paste the code from our Example Code section to replace code on page now, and save the page.
1 strings.xml file, This file has the text for our app_name string. No need to edit this page as app name already added when you created the app; and we are not
adding any additional text to our app.
, this page has the code for the Sdk versions and our support libraries code which is added at the 'dependencies' section.
This file is created for us when we created our android gradle/java/xml template app.
We do need to add the Sdk target version 21 code and the min Sdk version 14, because we are using Material Design
app theme for our theme. The Sdk
version 21 has already been added to the build.gradle file when we created our template app, and we don't need to add any support libraries for this
app so we don't need to edit this page.
For this app, the build.gradle file is located at; AppProjects/ViewAnimator/app/src.
1 manifest file; this page has many things necessary for our app like the 'intent filter', 'app theme name', and is where you can code things you may require like
'internet permissions', 'individual page names'.
This page is where you also code the name you gave your app theme. In this case, looking at the styles.xml
file at res/values-v21, we see that the name we gave it is AppTheme. This name needs to be coded in the androidmanifest.xml file in order for the app theme
to be applied to our app.
This has already been coded for us, so we don't need to edit this page.
Also, users on devices less than version 5.01 api21; will be shown holo.theme.light; already coded for us at styles.xml at the res/values folder of your app project. You can
also change the holo theme to the darker holo theme if you want to; coded as theme.holo
This section is for additional reading only, and not required for this app tutorials coding.
The Material Design platform was introduced in android 5.01 which is api 21, for coding purposes Sdk version 21. Each android platform build version has a API assigned to it.
View the Android Platform Versions and API Levels
You can find the android platform version of your android device at: Settings, AboutPhone.
For most apps you build you will need to have the proper Sdk version coded in either the build.gradle file or the AndroidManifest.xml file.
Android devices at this time support several different platforms. And there are many device users of all recent platforms; those being android version 4,5 6 7.
And since there are users using the various platforms, apps that are made need to have proper coding in order to perform as intended across all these platforms.
In order to provide support to make the apps you create compatible for all the different android platforms; android uses support libraries
as dependencies, and coded as such in your build.gradle file.
To make the apps you build compatible, you should at this time, use at least min Sdk version 14(for any added support libraries), and for target version Sdk version 21.
Doing so will make your app compatible with more android device platforms.
In addition to adding the Sdk min and target versions, you also need to add the 'support libraries' code for any
code class you add to your app that requires them like the CardView code class from Material Design.
And, Material Design is a good example because many code classes from material design require 'support libraries'. CardView, RecyclerView, SnackBar, Fab buttons,
are some of Material Design's UI widgets that require a support library.
How To add a 'support library' to your code:
Basically, you add a line or few lines of code to your build.gradle file at the 'dependencies' section. For example, any UI design features you want to add from
the Material Design coding classes requires the 'design' library to be added.
This is the code;
Android Developer website has the latest versions of these support libraries.
Features Material Design Support Library Using the Design Support Library
Quoted From Android Developer Website
"Note that as the Design library depends on the Support v4 and AppCompat Support Libraries, those will be included automatically
when you add the Design library dependency.
We also took care that these new widgets are usable in the Android Studio Layout Editor’s Design view (find them under CustomView), giving you an easier way to preview some
of these new components"(1)