Skip to content

PageScrollView widget is a customized ViewGroup having function like ScrollView & ViewPager but more efficient and extendable

License

Notifications You must be signed in to change notification settings

codingwithus/PageScrollView

Repository files navigation

PageScrollView

PageScrollView widget that is a customized ViewGroup having function like ScrollView & ViewPager .

the sample using interaction image,both use a simple PageScrollView without nest another ViewGroup:

can't show scrollview style imagecan't show viewpager style image

support basic function as below listed:

  • layout orientation either Horizontal and Vertical .
  • scroll any child to its start and end position to be fixed .
  • interface PageTransformer , OnPageChangeListener and OnScrollChangeListener ;
  • maxWidth&maxHeight,content gravity and all of its child layout_gravity .
  • smooth scroll any child to its start or centre with a optional offset and anim duration.

Why to Usage

  1. when you want use a simple ScrollView with some child ceiling top or bottom , or you don't like to nest a LinearLayout in it as usually,and your want a specified max width or height.
  2. when you need use a ViewPager to display different width and height child and can make any selected item center parent,or need add a header or footer view to its edge.

so don't hesitate to use PageScrollView , it can support all above interaction requirement.

How to Usage

For a working implementation of this project see the app/com.rexy folder.

  1. Edit layout xml file , add attr properties to PageScrollView,then include any child widgets in it just like in LinearLayout.

    <com.rexy.widget.PageScrollView android:id="@+id/pageScrollView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:minWidth="100dp"android:maxWidth="400dp"android:minHeight="100dp"android:maxHeight="900dp"android:orientation="horizontal"android:gravity="center"rexy:childCenter="true"rexy:floatViewEndIndex="-1"rexy:floatViewStartIndex="-1"rexy:middleMargin="10dp"rexy:overFlingDistance="0dp"rexy:viewPagerStyle="true"rexy:sizeFixedPercent="0"> <includelayout="@layout/merge_childs_layout" /> </com.rexy.widget.PageScrollView> 
  2. (Optional) In your onCreate method (or onCreateView for a fragment), set support properties as above attr do.

    //set PageScrollView as you need to overwriting the attr properities.PageScrollViewscrollView = (PageScrollView)findViewById(R.id.pageScrollView); //layout orientation HORIZONTAL or VERTICAL.scrollView.setOrientation(PageScrollView.VERTICAL); //only ViewPager style it will scroll as ViewPager and OnPageChangeListener can be efficientscrollView.setViewPagerStyle(false); //each item measure fixed size for percent of parent width or height.scrollView.setSizeFixedPercent(0); //which item to fixed scroll to start or end [0,pageScrollView.getItemCount()-1],-1 to ignore.scrollView.setFloatViewStartIndex(0); scrollView.setFloatViewEndIndex(pageScrollView.getItemCount()-1); //force layout all its childs gravity as Gravity.CENTER.scrollView.setChildCenter(true); //set layout margin for each item between at the layout orientation.scrollView.setMiddleMargin(30); //set max width or height for this container.scrollview.setMaxWidth(400); scrollview.setMaxHeigh(800);
  3. (Optional) bind event for PageScrollView.

    //continued from above scrollView.setPageHeadView(headerView); scrollView.setPageFooterView(footerView); scrollView.setPageTransformer(newPageScrollView.PageTransformer(){@OverridepublicvoidtransformPage(Viewview, floatposition, booleanhorizontal){//realized your transform animation for this view. } @OverridepublicvoidrecoverTransformPage(Viewview, booleanhorizontal){//clean your transform animation for this view. } }); PageScrollView.OnPageChangeListenerpagerScrollListener = newPageScrollView.OnPageChangeListener(){@OverridepublicvoidonPageScrolled(intposition, floatpositionOffset, intpositionOffsetPixels){//when selected item scroll from its center. } @OverridepublicvoidonPageSelected(intposition, intoldPosition){// position current selected item ,oldPosition previous selected item } @OverridepublicvoidonScrollChanged(intscrollX, intscrollY, intoldScrollX, intoldScrollY){//when content scrolled,see View.onScrollChanged } @OverridepublicvoidonScrollStateChanged(intstate, intoldState){// SCROLL_STATE_IDLE = 0; //scroll stopped .// SCROLL_STATE_DRAGGING = 1;//dragged scroll started .// SCROLL_STATE_SETTLING = 2;//fling scroll started . } }; scrollView.setOnScrollChangeListener(pagerScrollListener); scrollView.setOnPageChangeListener(pagerScrollListener);

About

PageScrollView widget is a customized ViewGroup having function like ScrollView & ViewPager but more efficient and extendable

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages