daimajia / AndroidImageSlider

An amazing and convenient Android image slider.
MIT License
5.63k stars 1.66k forks source link

Disable slide (not autocycle) when theres only one image? #82

Open deimian86 opened 9 years ago

deimian86 commented 9 years ago

How can I stop (and restart) the swipe gestures of a SliderLayout? I've got dinamic scenarios where I use a SliderLayout with only one image and sometimes with multiple images, or multiple images could be added dinamically.

When theres only one image I put the visibility of the indicators to View.GONE but I can still swipping the image. Is there a way to stop the swipe?

Thanks a lot for this amazing library and your work.

gloushkov commented 9 years ago

I also think that this is a must have feature.

Keep up the great work!

deimian86 commented 9 years ago

I overlap an ImageView with the first image over the Slider and change visibility when I receive the rest of the images, but it's only a patch.

jschleppy commented 9 years ago

This, and the fact that simply removing and adding slides dynamically makes it freak out and slide around a bunch on initializing is why I must ditch the use of this plugin. Great otherwise, look forward to this request being fulfilled.

felipe-silvestre-morais commented 9 years ago

I'm waiting for this feature too. For while I did a workaround:

I created a ghost view in my layout


<FrameLayout
    android:id="@+id/container_layout"
    android:background="@color/gray_hard_text"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <LinearLayout
                android:id="@+id/my_tickets_header"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/gray_hint">

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

        </LinearLayout>

    <FrameLayout
        android:id="@+id/ghost_view_workaround"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">

    </FrameLayout>

</FrameLayout>

In code, I check if my list has one element, if yes, I set the visibility to VISIBLE and set a listener to onclick

if (purchase.getOrder().getTickets().size() < 2) {
                viewHolder.findViewById(R.id.ghost_view_workaround).setVisibility(View.VISIBLE);
                viewHolder.findViewById(R.id.ghost_view_workaround).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
            }
confile commented 9 years ago

@daimajia It would be great if you could implement this feature. Thanks! Great work.

steffimueller commented 9 years ago

+1 please provide this feature!

romangromov commented 8 years ago

Why this is not yet supported? That's a pity..

confile commented 8 years ago

Is there any workaround for that?

dgngulcan commented 8 years ago

I've found a workaround I guess, this makes it unable to swipe but not sure if it will be stable :)

if (imageCount < 2) {
            sliderShow.stopAutoCycle();
            sliderShow.setPagerTransformer(false, new BaseTransformer() {
                @Override
                protected void onTransform(View view, float v) {
                }
            });
           //TODO: disable indicator
}
whoyouni commented 8 years ago

I donnot want it cycle,just one-way

gmikhail commented 8 years ago

@dgngulcan Thanks! Its works!

sgzsh269 commented 8 years ago

+1 definitely a must have feature!

jemsnaban commented 8 years ago

how to make it one way slider, it will stuck on last item and not cycling to the first item. thank you

ashishg656 commented 7 years ago

@dgngulcan Thanks a lot for this.

Joe-Mobarak commented 6 years ago

Thanks @dgngulcan

aruns2896 commented 5 years ago

I've found a workaround I guess, this makes it unable to swipe but not sure if it will be stable :)

if (imageCount < 2) {
            sliderShow.stopAutoCycle();
            sliderShow.setPagerTransformer(false, new BaseTransformer() {
                @Override
                protected void onTransform(View view, float v) {
                }
            });
           //TODO: disable indicator
}

@dgngulcan But it's affecting the other images when we using it with recycler views that is because the recycler view inflating the views in which the transformation has been done.

aruns2896 commented 5 years ago

@dgngulcan Can you have any solution for that using in recycler view??? Eagerly waiting for reply.............