<p >Sometimes you don't want an image to appear abruptly on the screen, rather you want to apply some kind of animation to the image when it transitions from one image to another. This is supported by android in the form of ImageSwitcher.</p>
<p >An image switcher allows you to add some transitions on the images through the way they appear on screen. In order to use image Switcher, you need to define its XML component first. Its syntax is given below −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="tag" ><ImageSwitcher</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/imageSwitcher1"</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_centerVertical</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ></ImageSwitcher></span></pre>
<p >Now we create an intance of ImageSwithcer in java file and get a reference of this XML component. Its syntax is given below −</p>
<pre class="result notranslate" >
private ImageSwitcher imageSwitcher;
imageSwitcher = (ImageSwitcher)findViewById(R.id.imageSwitcher1);
</pre>
<p >The next thing we need to do implement the ViewFactory interface and implement unimplemented method that returns an imageView. Its syntax is below −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pln" >imageSwitcher</span><span class="pun" >.</span><span class="pln" >setImageResource</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >ic_launcher</span><span class="pun" >);</span><span class="pln" >
imageSwitcher</span><span class="pun" >.</span><span class="pln" >setFactory</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >ViewFactory</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="typ" >View</span><span class="pln" > makeView</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="typ" >ImageView</span><span class="pln" > myView </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >ImageView</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >());</span><span class="pln" >
</span><span class="kwd" >return</span><span class="pln" > myView</span><span class="pun" >;</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="pun" >}</span></pre>
<p >The last thing you need to do is to add Animation to the ImageSwitcher. You need to define an object of Animation class through AnimationUtilities class by calling a static method loadAnimation. Its syntax is given below −</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="typ" >Animation</span><span class="pln" > </span><span class="kwd" >in</span><span class="pln" > </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >AnimationUtils</span><span class="pun" >.</span><span class="pln" >loadAnimation</span><span class="pun" >(</span><span class="kwd" >this</span><span class="pun" >,</span><span class="pln" >android</span><span class="pun" >.</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >anim</span><span class="pun" >.</span><span class="pln" >slide_in_left</span><span class="pun" >);</span><span class="pln" >
imageSwitcher</span><span class="pun" >.</span><span class="pln" >setInAnimation</span><span class="pun" >(</span><span class="kwd" >in</span><span class="pun" >);</span><span class="pln" >
imageSwitcher</span><span class="pun" >.</span><span class="pln" >setOutAnimation</span><span class="pun" >(</span><span class="kwd" >out</span><span class="pun" >);</span><span class="pln" > </span></pre>
<p >The method setInAnimaton sets the animation of the appearance of the object on the screen whereas setOutAnimation does the opposite. The method loadAnimation() creates an animation object.</p>
<p >Apart from these methods, there are other methods defined in the ImageSwitcher class. They are defined below −</p>
<table class="table table-bordered" >
<tbody >
<tr >
<th >Sr.No</th>
<th >Method & description</th>
</tr>
<tr >
<td >1</td>
<td ><b >setImageDrawable(Drawable drawable)</b>
<p >Sets an image with image switcher. The image is passed in the form of bitmap</p>
</td>
</tr>
<tr >
<td >2</td>
<td ><b >setImageResource(int resid)</b>
<p >Sets an image with image switcher. The image is passed in the form of integer id</p>
</td>
</tr>
<tr >
<td >3</td>
<td ><b >setImageURI(Uri uri)</b>
<p >Sets an image with image switcher. THe image is passed in the form of URI</p>
</td>
</tr>
<tr >
<td >4</td>
<td ><b >ImageSwitcher(Context context, AttributeSet attrs)</b>
<p >Returns an image switcher object with already setting some attributes passed in the method</p>
</td>
</tr>
<tr >
<td >5</td>
<td ><b >onInitializeAccessibilityEvent (AccessibilityEvent event)</b>
<p >Initializes an AccessibilityEvent with information about this View which is the event source</p>
</td>
</tr>
<tr >
<td >6</td>
<td ><b >onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)</b>
<p >Initializes an AccessibilityNodeInfo with information about this view</p>
</td>
</tr>
</tbody>
</table>
<h2 >Example</h2>
<p >The below example demonstrates some of the image switcher effects on the bitmap. It crates a basic application that allows you to view the animation effects on the images.</p>
<p >To experiment with this example , you need to run this on an actual device.</p>
<table class="table table-bordered" >
<tbody >
<tr >
<th >Steps</th>
<th >Description</th>
</tr>
<tr >
<td >1</td>
<td >You will use Android studio IDE to create an Android application under a package com.example.sairamkrishna.myapplication. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.</td>
</tr>
<tr >
<td >2</td>
<td >Modify src/MainActivity.java file to add necessary code.</td>
</tr>
<tr >
<td >3</td>
<td >Modify the res/layout/activity_main to add respective XML components</td>
</tr>
<tr >
<td >4</td>
<td >Run the application and choose a running android device and install the application on it and verify the results</td>
</tr>
</tbody>
</table>
<p >Following is the content of the modified main activity file<b >src/MainActivity.java</b>.</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >sairamkrishna</span><span class="pun" >.</span><span class="pln" >myapplication</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Activity</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >ActionBar</span><span class="pun" >.</span><span class="typ" >LayoutParams</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >Activity</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >os</span><span class="pun" >.</span><span class="typ" >Bundle</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >Menu</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >MenuItem</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >view</span><span class="pun" >.</span><span class="typ" >View</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Button</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >ImageSwitcher</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >ImageView</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Toast</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >ViewSwitcher</span><span class="pun" >.</span><span class="typ" >ViewFactory</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >Activity</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="kwd" >private</span><span class="pln" > </span><span class="typ" >ImageSwitcher</span><span class="pln" > sw</span><span class="pun" >;</span><span class="pln" >
</span><span class="kwd" >private</span><span class="pln" > </span><span class="typ" >Button</span><span class="pln" > b1</span><span class="pun" >,</span><span class="pln" >b2</span><span class="pun" >;</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >protected</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onCreate</span><span class="pun" >(</span><span class="typ" >Bundle</span><span class="pln" > savedInstanceState</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onCreate</span><span class="pun" >(</span><span class="pln" >savedInstanceState</span><span class="pun" >);</span><span class="pln" >
setContentView</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" >
b1 </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button</span><span class="pun" >);</span><span class="pln" >
b2 </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >Button</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button2</span><span class="pun" >);</span><span class="pln" >
sw </span><span class="pun" >=</span><span class="pln" > </span><span class="pun" >(</span><span class="typ" >ImageSwitcher</span><span class="pun" >)</span><span class="pln" > findViewById</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >imageSwitcher</span><span class="pun" >);</span><span class="pln" >
sw</span><span class="pun" >.</span><span class="pln" >setFactory</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >ViewFactory</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="typ" >View</span><span class="pln" > makeView</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="typ" >ImageView</span><span class="pln" > myView </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >ImageView</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >());</span><span class="pln" >
myView</span><span class="pun" >.</span><span class="pln" >setScaleType</span><span class="pun" >(</span><span class="typ" >ImageView</span><span class="pun" >.</span><span class="typ" >ScaleType</span><span class="pun" >.</span><span class="pln" >FIT_CENTER</span><span class="pun" >);</span><span class="pln" >
myView</span><span class="pun" >.</span><span class="pln" >setLayoutParams</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >ImageSwitcher</span><span class="pun" >.</span><span class="typ" >LayoutParams</span><span class="pun" >(</span><span class="typ" >LayoutParams</span><span class="pun" >.</span><span class="pln" >WRAP_CONTENT</span><span class="pun" >,</span><span class="typ" >LayoutParams</span><span class="pun" >.</span><span class="pln" >WRAP_CONTENT</span><span class="pun" >));</span><span class="pln" >
</span><span class="kwd" >return</span><span class="pln" > myView</span><span class="pun" >;</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="pun" >});</span><span class="pln" >
b1</span><span class="pun" >.</span><span class="pln" >setOnClickListener</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >View</span><span class="pun" >.</span><span class="typ" >OnClickListener</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onClick</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > v</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >(),</span><span class="pln" > </span><span class="str" >"previous Image"</span><span class="pun" >,</span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_LONG</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" >
sw</span><span class="pun" >.</span><span class="pln" >setImageResource</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >abc</span><span class="pun" >);</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="pun" >});</span><span class="pln" >
b2</span><span class="pun" >.</span><span class="pln" >setOnClickListener</span><span class="pun" >(</span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >View</span><span class="pun" >.</span><span class="typ" >OnClickListener</span><span class="pun" >()</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onClick</span><span class="pun" >(</span><span class="typ" >View</span><span class="pln" > v</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="pln" >getApplicationContext</span><span class="pun" >(),</span><span class="pln" > </span><span class="str" >"Next Image"</span><span class="pun" >,</span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_LONG</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" >
sw</span><span class="pun" >.</span><span class="pln" >setImageResource</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >drawable</span><span class="pun" >.</span><span class="pln" >tp</span><span class="pun" >);</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="pun" >});</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onCreateOptionsMenu</span><span class="pun" >(</span><span class="typ" >Menu</span><span class="pln" > menu</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="com" >// Inflate the menu; this adds items to the action bar if it is present.</span><span class="pln" >
getMenuInflater</span><span class="pun" >().</span><span class="pln" >inflate</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >menu</span><span class="pun" >.</span><span class="pln" >menu_main</span><span class="pun" >,</span><span class="pln" > menu</span><span class="pun" >);</span><span class="pln" >
</span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="lit" >@Override</span><span class="pln" >
</span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >boolean</span><span class="pln" > onOptionsItemSelected</span><span class="pun" >(</span><span class="typ" >MenuItem</span><span class="pln" > item</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="com" >// Handle action bar item clicks here. The action bar will</span><span class="pln" >
</span><span class="com" >// automatically handle clicks on the Home/Up button, so long</span><span class="pln" >
</span><span class="com" >// as you specify a parent activity in AndroidManifest.xml.</span><span class="pln" >
</span><span class="kwd" >int</span><span class="pln" > id </span><span class="pun" >=</span><span class="pln" > item</span><span class="pun" >.</span><span class="pln" >getItemId</span><span class="pun" >();</span><span class="pln" >
</span><span class="com" >//noinspection SimplifiableIfStatement</span><span class="pln" >
</span><span class="kwd" >if</span><span class="pln" > </span><span class="pun" >(</span><span class="pln" >id </span><span class="pun" >==</span><span class="pln" > R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >action_settings</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" >
</span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >true</span><span class="pun" >;</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="kwd" >return</span><span class="pln" > </span><span class="kwd" >super</span><span class="pun" >.</span><span class="pln" >onOptionsItemSelected</span><span class="pun" >(</span><span class="pln" >item</span><span class="pun" >);</span><span class="pln" >
</span><span class="pun" >}</span><span class="pln" >
</span><span class="pun" >}</span></pre>
<p >Following is the modified content of the xml<b >res/layout/activity_main.xml</b>.</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="tag" ><RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/tools"</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"match_parent"</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_horizontal_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" >
</span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >"@dimen/activity_vertical_margin"</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >".MainActivity"</span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Gestures Example"</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textview"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"35dp"</span><span class="pln" >
</span><span class="atn" >android:layout_alignParentTop</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><TextView</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"Tutorials point"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/textView"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textview"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >"#ff7aff24"</span><span class="pln" >
</span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >"35dp"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><ImageSwitcher</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >"@+id/imageSwitcher"</span><span class="pln" >
</span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >"@+id/textView"</span><span class="pln" >
</span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >"168dp"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="<"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
</span><span class="tag" ><Button</span><span class="pln" >
</span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >"wrap_content"</span><span class="pln" >
</span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >"></span><span class="pln" >"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button" />
</span><span class="tag" ></RelativeLayout></span></pre>
<p >Following is the content of<b >AndroidManifest.xml</b>file.</p>
<pre class="prettyprint notranslate prettyprinted" >
<span class="pun" ><?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >"1.0"</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >"utf-8"</span><span class="pun" >?></span><span class="pln" >
</span><span class="tag" ><manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >"http://schemas.android.com/apk/res/android"</span><span class="pln" >
</span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >"com.example.imageswitcher"</span><span class="pln" >
</span><span class="atn" >android:versionCode</span><span class="pun" >=</span><span class="atv" >"1"</span><span class="pln" >
</span><span class="atn" >android:versionName</span><span class="pun" >=</span><span class="atv" >"1.0"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><application</span><span class="pln" >
</span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >"true"</span><span class="pln" >
</span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >"@drawable/ic_launcher"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" >
</span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >"@style/AppTheme"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><activity</span><span class="pln" >
</span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"com.example.sairamkrishna.myapplication.MainActivity"</span><span class="pln" >
</span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >"@string/app_name"</span><span class="pln" > </span><span class="tag" >></span><span class="pln" >
</span><span class="tag" ><intent-filter></span><span class="pln" >
</span><span class="tag" ><action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.action.MAIN"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ><category</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >"android.intent.category.LAUNCHER"</span><span class="pln" > </span><span class="tag" >/></span><span class="pln" >
</span><span class="tag" ></intent-filter></span><span class="pln" >
</span><span class="tag" ></activity></span><span class="pln" >
</span><span class="tag" ></application></span><span class="pln" >
</span><span class="tag" ></manifest></span></pre>
<p >Let's try to run your application we just modified. I assume you had created your<b >AVD</b>while doing environment setup. To run the app from Android studio, open one of your project's activity files and click Run<img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" />icon from the toolbar. Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window −</p>
<p><img alt="Android Image Switcher Tutorial" src="http://www.tutorialspoint.com/android/images/image_switcher.jpg" /></p>
<p >Now if you will look at your device screen , you will see the two buttons.</p>
<p >Now just select the upper button that right arrow. An image would appear from right and move towards left. It is shown below −</p>
<p><img alt="Android Image Switcher Tutorial" src="http://www.tutorialspoint.com/android/images/image_switcher1.jpg" /></p>
<p >Now tap on the below button, that will bring back the previous image with some transition. It is shown below −</p>
<p><img alt="Android Image Switcher Tutorial" src="http://www.tutorialspoint.com/android/images/image_switcher2.jpg" /></p>
<div></div>