felipecsl / AsymmetricGridView

Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span
http://felipecsl.com/AsymmetricGridView
MIT License
1.84k stars 431 forks source link

AsymmetricGridView

Android Arsenal Build Status

An Android custom ListView that implements multiple columns and variable sized elements.

Please note that this is currently in a preview state. This basically means that the API is not fixed and you should expect changes between releases.

Sample application:

Try out the sample application on Google Play

Gplay

Screenshots:

screenshot 1 screenshot 2 screenshot 3 screenshot 4

Usage

Version 2.0.0 includes a major breaking change to the AsymmetricGridViewAdapter. You now provide your own adapter to the AsymmetricGridViewAdapter constructor instead of extending it.

In your build.gradle file:

dependencies {
    implementation 'com.felipecsl.asymmetricgridview:library:2.0.1'
}

In your layout xml:

<com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

In your activity class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (AsymmetricGridView) findViewById(R.id.listView);

    // Choose your own preferred column width
    listView.setRequestedColumnWidth(Utils.dpToPx(this, 120));
    final List<AsymmetricItem> items = new ArrayList<>();

    // initialize your items array
    adapter = new ListAdapter(this, listView, items);
    AsymmetricGridViewAdapter asymmetricAdapter =
        new AsymmetricGridViewAdapter<>(this, listView, adapter);
    listView.setAdapter(asymmetricAdapter);
}

Whenever your adapter changes (add or remove items), the grid will automatically reflect those changes by subscribing to your adapter changes.

Toggle to enable/disable reordering of elements to better fill the grid

// Setting to true will move items up and down to better use the space
// Defaults to false.
listView.setAllowReordering(true);

listView.isAllowReordering(); // true

Snapshots of the development version are available in Sonatype's snapshots repository.

Works with Android 2.3.x and above.

Caveats

Contributing

Copyright and license

Code and documentation copyright 2011-2015 Felipe Lima. Code released under the MIT license.