Giter Site home page Giter Site logo

jason-cooke / materialpagerrecyclergridview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ckdevrel/materialpagerrecyclergridview

1.0 1.0 0.0 693 KB

It is a RecyclerView using GridLayoutManager with header layout as ViewPager.

Home Page: http://takeoffandroid.com/

License: Other

Java 100.00%

materialpagerrecyclergridview's Introduction

Android Arsenal

Buy Me a Coffee at ko-fi.com

MaterialPagerRecyclerGridView

It is a RecyclerView using GridLayoutManager with header layout as ViewPager. This can be easily customized according to the usage.

Customization

Here I have used images for adapters and view pagers from arrays.xml:. You can use your own images or can even load images from the url using picasso, glide, UIL or whatever in to the adapter and view pager.

Images for GridItems

Pass your images into the adapter classes as like below

// where R.arrays.xml are images from the drawable folder.
final MainAdapter adapter = new MainAdapter(this, R.array.icons);

The MainAdapter is nothing but a adapter class for RecyclerView wher you pass a images for griditems.

Images for ViewPagers

// I am passing the same list of images that I have used for GridItems. You can use your own instead of **mImageResID**.
ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(mContext, mImageResID);

The ViewPagerAdapter is a class for ViewPager and it is found inside MainAdapter.

Note: You can even pass ArrayList and customize your layout for the combination of both images and texts or whatever according to your requirement. I have used layout with ImageViews in this repo only for the sample purpose.

Points to be remember

There are certain special aspects that must be followed before customizing your layout.

List count:

The list count should always be +1 (i.e)

 @Override
    public int getItemCount() {
        return (mContext.getResources().getIntArray(mImageResID).length) + HEADER_PAGER_LAYOUT;
    }
    

where HEADER_PAGER_LAYOUT is a static variable with value 1

List position:

In order to get the exact position of the particular item in a list.

you have to -1 from the current positon(i.e)

@Override
    public void onClick(View view) {

        mOnGridItemSelectedListener.onGridItemClick(view,getAdapterPosition() - HEADER_PAGER_LAYOUT);
    }
    

where HEADER_PAGER_LAYOUT is a static variable with value 1

materialpagerrecyclergridview's People

Stargazers

Mohammed Hasanul Chowdhury avatar

Watchers

James Cloos 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.