AndroidManifest.xml file

XML




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.w3wiki.myfirstkotlinapp">
  
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
  
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
  
</manifest>


ImageSwitcher in Kotlin

Android ImageSwitcher is a user interface widget that provides a smooth transition animation effect to the images while switching between them to display in the view. 

ImageSwitcher is subclass of View Switcher which is used to animates one image and displays next one.
Generally, we use ImageSwitcher in two ways manually in XML layout and programmatically in Kotlin file.

We should define an XML component, to use ImageSwitcher in our android application. 

XML




<ImageSwitcher android:id="@+id/imgSw"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ImageSwitcher>


First we create a new project by following the below steps: 

  1. Click on File, then New => New Project.
  2. After that include the Kotlin support and click on next.
  3. Select the minimum SDK as per convenience and click next button.
  4. Then select the Empty activity => next => finish.

Similar Reads

Different attributes of ImageSwitcher widget

...

Modify activity_main.xml file

XML attributes Description android:id Used to specify the id of the view. android:onClick Used to specify the action when this view is clicked. android:background Used to set the background of the view. android:padding Used to set the padding of the view. android:visibility Used to set the visibility of the view. android:inAnimation Used to define the animation to use when view is shown. android:outAnimation Used to define the animation to use when view is hidden. android:animateFirstView Used to define whether to animate the current view when the view animation is first displayed....

Update strings.xml file

In this file, we use constraint layout with ImageSwitcher and Buttons....

Different methods of ImageSwitcher widget

...

Access ImageSwitcher in MainActivity.kt file

Here, we update the name of the application using the string tag....

AndroidManifest.xml file

...

Run as Emulator:

Methods Description setImageDrawable It is used to set a new drawable on the next ImageView in the switcher. setImageResource It is used to set a new image on the ImageSwitcher with the given resource id. setImageURI It is used to set a new image on the ImageSwitcher with the given URI....

Contact Us