Output:
1/ Create A New Project. and use this Library in build.gradle file
implementation("com.github.denzcoskun:ImageSlideshow:0.1.2"
2/ Below is the full code of the build.gradle file
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
android {
namespace = "com.microappvalley.androidautoimagesliderexamplekotlin"
compileSdk = 35
defaultConfig {
applicationId = "com.microappvalley.androidautoimagesliderexamplekotlin"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation("com.github.denzcoskun:ImageSlideshow:0.1.2")
}
3/ Open Settings.Gradle and modify this line
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}
4/ Below is the full code of the settings.gradle file
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}
rootProject.name = "Android Auto Image Slider Example kotlin"
include(":app")
5/ Modify the activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.cardview.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_margin="10dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="10dp">
<com.denzcoskun.imageslider.ImageSlider
android:id="@+id/imageslider"
android:layout_width="match_parent"
android:layout_height="220dp"
app:iss_auto_cycle="true"
app:iss_corner_radius="10"
app:iss_delay="1000"
app:iss_period="1000"
app:iss_selected_dot="@drawable/default_selected_dot" />
</androidx.cardview.widget.CardView>
</LinearLayout>
6/ Modify the MainActivity.kt file
package com.microappvalley.androidautoimagesliderexamplekotlin
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.denzcoskun.imageslider.ImageSlider
import com.denzcoskun.imageslider.constants.ScaleTypes
import com.denzcoskun.imageslider.models.SlideModel
class MainActivity : AppCompatActivity() {
lateinit var imageslider: ImageSlider
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
imageslider = findViewById(R.id.imageslider)
val slideModels = ArrayList<SlideModel>()
slideModels.add(SlideModel(R.drawable.img1, ScaleTypes.FIT))
slideModels.add(SlideModel(R.drawable.img2, ScaleTypes.FIT))
slideModels.add(SlideModel(R.drawable.img3, ScaleTypes.FIT))
imageslider.setImageList(slideModels, ScaleTypes.FIT)
}
}