SCViewPager Documentation

repository·master·Indexed 21 days ago

https://github.com/sacot41/scviewpager

An Android library that extends ViewPager to provide scroll-based animations inspired by the iOS JazzHands library. It allows developers to animate views based on ViewPager scroll positions using SCViewAnimation and SCPositionAnimation.

Tokens
805
Snippets
3
Records
3
Agent score
24%

What's inside SCViewPager

  1. Animate views based on ViewPager scroll

    master

    To create scroll-based animations, follow these steps in your Activity:

    1. Retrieve the display size using SCViewAnimationUtil.getDisplaySize(context).
    2. Identify the view you want to animate.
    3. Create an SCViewAnimation instance for that view.
    4. Configure the animation using startToPosition and addPageAnimation (e.g., using SCPositionAnimation).
    5. Register the animation with your SCViewPager instance using addAnimation(viewAnimation).

    Note: Ensure you have already set the SCViewPager adapter before adding animations.

    Point size = SCViewAnimationUtil.getDisplaySize(this);
    
    View view = findViewById(R.id.textview_to_animate);
    SCViewAnimation viewAnimation = new SCViewAnimation(view);
    viewAnimation.startToPosition((int)(size.x*1.5), null);
    viewAnimation.addPageAnimation(new SCPositionAnimation(this, 0, -(int)(size.x*1.5), 0));
    mViewPager.addAnimation(viewAnimation);
  2. Add SCViewPager to your XML layout

    master

    Include the com.dev.sacot41.scviewpager.SCViewPager component in your layout file. You can then place other views (like TextView) on top of it to serve as the targets for scroll-based animations.

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <com.dev.sacot41.scviewpager.SCViewPager
            android:id="@+id/viewpager_main_activity"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </com.dev.sacot41.scviewpager.SCViewPager>
    
        <TextView
            android:id="@+id/textview_to_animate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:text="@string/textview_bonjour"/>
    
    </RelativeLayout>