Coder Social home page Coder Social logo

dharmakshetri / greedo-layout-for-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 500px/greedo-layout-for-android

0.0 2.0 0.0 1.53 MB

Full aspect ratio grid LayoutManager for Android's RecyclerView

License: MIT License

Java 100.00%

greedo-layout-for-android's Introduction

Greedo Layout for Android

A drop-in custom layout manager for Android RecyclerViews to layout a grid of photos while respecting their aspect ratios.

image

Setup

Download the latest release via Gradle:

repositories {
	maven { url 'https://github.com/500px/greedo-layout-for-android/raw/master/releases/' }
}

dependencies {
	compile 'com.fivehundredpx:greedo-layout:1.0.0'
}

Usage

See the sample project for a complete solution on how to use GreedoLayout. Below are the specific steps.

// Create an instance of the GreedoLayoutManager and pass it to the RecyclerView
MyRecyclerAdapter recyclerAdapter = new MyRecyclerAdapter(this);
GreedoLayoutManager layoutManager = new GreedoLayoutManager(recyclerAdapter);

RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(recyclerAdapter);

// Set the max row height in pixels
layoutManager.setMaxRowHeight(300);

// If you would like to add spacing between items (Note, MeasUtils is in the sample project)
int spacing = MeasUtils.dpToPx(4, this);
recyclerView.addItemDecoration(new GreedoSpacingItemDecoration(spacing));

And then, in your RecyclerView adapter, or some other class of your choosing, implement SizeCalculatorDelegate. This implementation got passed to the layout manager above.

public class MyRecyclerAdapter extends RecyclerView.Adapter<ViewHolder> implements SizeCalculatorDelegate {
    @Override
    public double aspectRatioForIndex(int index) {
    	// Return the aspect ratio of your image at the given index
    }
}

License

GreedoLayout is released under the MIT license. See LICENSE for details.

greedo-layout-for-android's People

Contributors

jvillella avatar itspriyesh avatar veyndan avatar mck182 avatar anurlybayev avatar

Watchers

James Cloos avatar Dharma Kshetri 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.