Fit Grid View

Additional

Language
Java
Version
v1.0.5 (Aug 18, 2017)
Created
Dec 23, 2016
Updated
Mar 5, 2018 (Retired)
Owner
Selçuk Ege Aker (ceryle)
Contributor
Selçuk Ege Aker (ceryle)
1
Activity
Badge
Generate
Download
Source code

FitGridView


In this library, GridView is extended with a few methods to achieve fitting it to a given size.

Preview

Installation

Gradle

Add it to your build.gradle with:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and:

dependencies {
    compile 'com.github.ceryle:FitGridView:v1.0.5'
}

Customization

Some Attributes

Segmented Button

Option Name Format Description
app:row integer number of rows
app:column integer number of colums

Examples

In Xml Layout
<co.ceryle.fitgridview.FitGridView
     android:id="@+id/gridView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:listSelector="@android:color/transparent"
     app:column="3"
     app:row="4"/>
In Java
in your main activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    gridView = (FitGridView) findViewById(R.id.gridView);
    gridView.setFitGridAdapter(new Adapter(this));
        
    // you can change grid view size any time. don't forget calling update method.
    changeSize(4, 4);
}
        
private void changeSize(int r, int c) {
     gridView.setRow(r);
     gridView.setColumn(c);
     gridView.update();
}
in your adapter:
// In adapter, you can define your grid size by passing it to super method.
int dataSize = 15;
Adapter(Context context) {
        super(context, R.layout.grid_item, dataSize);
        this.context = context;
}

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details