Code Monkey home page Code Monkey logo

expandablepager's Introduction

Download Android Arsenal

ExpandablePager

Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed).

alt tag #Requirements Android 4.0+ (Ice Cream Sandwich and later) #Setup ###Step 1 Add the following line to the dependencies section of your build.gradle file

compile 'com.telenav.expandablepager:expandablepager:0.2.1'

###Step 2 Extend desired adapter:

  • ExpandablePagerAdapter (don't forget to override instantiateItem)
public class MyAdapter extends ExpandablePagerAdapter<Book> {
    
    ...

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final ViewGroup rootView = (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.page, container, false); //inflate view

        ...

        return attach(container, rootView, position); //don't forget to return the result of attach()
    }
}
  • ExpandableFragmentPagerAdapter
  • ExpandableFragmentStatePagerAdapter

###Step 3 Add ExpandablePager to a layout

<?xml version="1.0" encoding="utf-8"?>
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.telenav.expandablepager.ExpandablePager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true" /> //pin the pager to the bootom of the screen using layout_gravity or layout_alignParentBottom
</RelativeLayout>

###Step 4 Create and pass your adapter to the ExpandablePager

    MyAdapter adapter = new MyAdapter(myData);
    ExpandablePager pager = (ExpandablePager) findViewById(R.id.container);
    pager.setAdapter(adapter);

###Step 5 (optional)

  • Set collapsed height & animation duration via xml
    app:animation_duration="200"
    app:collapsed_height="@dimen/header_height"

or programmatically

    pager.setAnimationDuration(duration);
    pager.setCollapsedHeight((int) getResources().getDimension(R.dimen.header_height));
  • Set display mode (MODE_REGULAR or MODE_FIXED)
    pager.setMode(ExpandablePager.MODE_REGULAR);

#Extras Change pager state (supported states are STATE_COLLAPSED, STATE_EXPANDED, and STATE_HIDDEN)

    pager.setState(ExpandablePager.STATE_COLLAPSED)

Animate pager state change

    pager.animateToState(ExpandablePager.STATE_COLLAPSED)

Set current item

    pager.setCurrentItem(index, false);

Set listeners

    pager.setOnSliderStateChangeListener(new OnSliderStateChangeListener() {

        @Override
        public void onStateChanged(View page, int index, int state) {
            ...
        }

        @Override
        public void onPageChanged(View page, int index, int state) {
            ...
        }
    });
    
    pager.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(List<?> items, int index) {
            ...
        }
    });

#Sample For a more detailed example check the demoapp module.

#License Apache License, Version 2.0

expandablepager's People

Contributors

dimatim avatar

Watchers

James Cloos avatar kobihcmomanyi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.