Fabio Piunti
Fabio Piunti

Reputation: 49

Animation slidin ViewPager with image that change

i would create a slider like this: THIS

I haven't trouble to create an activity that does this things, my problem is that i can't create the animation for the images(The littel circle) that are on the bottom. I have tested this, but it is to slow:

@Override
    public Fragment getItem(int position) {
        ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
        Bundle args = new Bundle();
        args.putInt("key", position);
        fragment.setArguments(args);

        switch (position){
            case 0:
                findViewById(R.id.btnFirstSlide).setVisibility(View.VISIBLE);
                findViewById(R.id.btnSecondSlide).setVisibility(View.INVISIBLE);
                findViewById(R.id.btnThirdSlide).setVisibility(View.INVISIBLE);
                break;
            case 1:
                findViewById(R.id.btnFirstSlide).setVisibility(View.INVISIBLE);
                findViewById(R.id.btnSecondSlide).setVisibility(View.VISIBLE);
                findViewById(R.id.btnThirdSlide).setVisibility(View.INVISIBLE);
                break;
            case 2:
                findViewById(R.id.btnFirstSlide).setVisibility(View.INVISIBLE);
                findViewById(R.id.btnSecondSlide).setVisibility(View.INVISIBLE);
                findViewById(R.id.btnThirdSlide).setVisibility(View.VISIBLE);
                break;

        }

        return fragment;
    }

What can be a nice solution?

Upvotes: 1

Views: 114

Answers (1)

Yasin Kaçmaz
Yasin Kaçmaz

Reputation: 6663

Did you see ViewPagerIndicator : JakeWharton/ViewPagerIndicator

Its easy to use like :

In xml :

<com.viewpagerindicator.CirclePageIndicator
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/indicator"
    android:padding="20dip"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    app:centered="true"
    app:fillColor="@color/ColorPrimary"
    app:pageColor="@color/Transparent"
    app:radius="7dp"
    app:snap="false"
    app:strokeColor="@color/White"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

And in your code:

circlePageIndicator=(CirclePageIndicator)findViewById(R.id.indicator);
circlePageIndicator.setViewPager(viewpager);

There is so many different indicators in that library you can try all of them and choose whatever you want .

Just add this line to your build.gradle : compile 'com.viewpagerindicator:library:2.4.1@aar'

Upvotes: 1

Related Questions