Carousel in Android
VIDEO
FOLLOW THESE STEPS
Step 1: build.gradle
implementation 'com.github.denzcoskun:ImageSlideshow:0.1.0'
Step 2: settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Step 3: res > layout > activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.denzcoskun.imageslider.ImageSlider
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/black"
app:iss_auto_cycle="true"
app:iss_delay="0"
app:iss_text_align="CENTER"
app:iss_period="3000"
app:iss_placeholder="@color/black"
app:iss_error_image="@color/purple_700"
android:id="@+id/slider"
app:iss_corner_radius="0"
/>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/slider"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="186dp"
android:gravity="center"
android:text="THIS IS CAROUSEL"
android:textAlignment="center"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
Step 4: MainActivity.class
package com.heycolleagues.carousel;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.denzcoskun.imageslider.ImageSlider;
import com.denzcoskun.imageslider.constants.ScaleTypes;
import com.denzcoskun.imageslider.models.SlideModel;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ImageSlider imageSlider = findViewById(R.id.slider);
// List<SlideModel> slideModels = new ArrayList<>();
// slideModels.add(new SlideModel(R.drawable.spider, ScaleTypes.FIT));
// slideModels.add(new SlideModel(R.drawable.jack, ScaleTypes.FIT));
// slideModels.add(new SlideModel(R.drawable.ozark, ScaleTypes.FIT));
// slideModels.add(new SlideModel(R.drawable.retro, ScaleTypes.FIT));
List<SlideModel> imageList = new ArrayList<>(); // Create image list
// imageList.add(SlideModel("String Url" or R.drawable)
// imageList.add(SlideModel("String Url" or R.drawable, "title") You can add title
imageList.add(new SlideModel("https://bit.ly/2YoJ77H", "Title 1", ScaleTypes.FIT));
imageList.add(new SlideModel("https://bit.ly/2BteuF2", "Title 2", ScaleTypes.FIT));
imageList.add(new SlideModel("https://bit.ly/3fLJf72", "Title 3", ScaleTypes.FIT));
imageList.add(new SlideModel(R.drawable.image, "Title 4", ScaleTypes.FIT));
imageList.add(new SlideModel(R.drawable.imagee, "Title 5", ScaleTypes.FIT));
imageList.add(new SlideModel(R.drawable.imageee, "Title 6", ScaleTypes.FIT));
ImageSlider imageSlider = findViewById(R.id.slider);
imageSlider.setImageList(imageList);
}
}