Skip to content
Massimo Biolcati edited this page May 9, 2015 · 1 revision

After you finished the configuration, you can start to using this.

Step 1

Add SliderLayout to your layout.

<com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="200dp"
/>

Step 2

Get the SliderLayout instance by invoking findViewById. For example:

SliderLayout sliderShow = (SliderLayout) findViewById(R.id.slider);

Step3

Let's make a slider, and add it into the sliderShow.

TextSliderView textSliderView = new TextSliderView(this);
textSliderView
	.description("Game of Thrones")
	.image("http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg");
	
sliderShow.addSlider(textSliderView);

Note! To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed:

@Override
protected void onStop() {
    sliderShow.stopAutoCycle();
    super.onStop();
}

There are two preset slider shows you can choose.

Show Type Description
DefaultSliderView a default slider view, which can only show images.
TextSliderView a slider view which can show images with description text.

Of course, you can customize your own slider view, and are welcome to contribute your own amazing custom slider views.


There also are some functions to change the properties of the SliderLayout.

For example:

Method Description
setPresetTransformer Choose from 15 provided view transition effects
setPresetIndicator Choose from 6 provided indicator styles
setIndicatorVisibility Set the visibility of indicators
setSliderTransformDuration Set the duration of slideshow transitions
startAutoCycle Start auto cycle
stopAutoCycle Stop auto cycle
setDuration Set the duration to display each slide
Clone this wiki locally