
In this library, GridView is extended with a few methods to achieve fitting it to a given size.
Add it to your build.gradle with:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}and:
dependencies {
compile 'com.github.ceryle:FitGridView:v1.0.5'
}| Option Name | Format | Description |
|---|---|---|
| app:row | integer | number of rows |
| app:column | integer | number of colums |
<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"/>@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (FitGridView) findViewById(R.id.gridView);
gridView.setFitGridAdapter(newAdapter(this));
// you can change grid view size any time. don't forget calling update method.changeSize(4, 4);
}
privatevoidchangeSize(intr, intc) {
gridView.setRow(r);
gridView.setColumn(c);
gridView.update();
}// In adapter, you can define your grid size by passing it to super method.intdataSize = 15;
Adapter(Contextcontext) {
super(context, R.layout.grid_item, dataSize);
this.context = context;
}This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details
