Add an array of buttons to a GridView in an Android application

In the following code, you should change the upper limits of the for to a variable. public class MainActivity extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TableLayout layout = new TableLayout (this); layout.setLayoutParams( new TableLayout.LayoutParams(4,5) ); layout.setPadding(1,1,1,1); for (int f=0; f<=13; f++) { TableRow tr = new TableRow(this); for (int … Read more

gridView with different cells sizes, pinterest style

Is it a bit late to answer? check this library from etsy. it looks very promising. https://github.com/etsy/AndroidStaggeredGrid I think it is newer version of https://github.com/maurycyw/StaggeredGridView . Updated. Try using RecyclerView StaggeredGridLayoutManager from google instead RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(adapter);

Gridview with two columns and auto resized images

Here’s a relatively easy method to do this. Throw a GridView into your layout, setting the stretch mode to stretch the column widths, set the spacing to 0 (or whatever you want), and set the number of columns to 2: res/layout/main.xml <?xml version=”1.0″ encoding=”utf-8″?> <FrameLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent”> <GridView android:id=”@+id/gridview” android:layout_width=”match_parent” android:layout_height=”match_parent” android:verticalSpacing=”0dp” android:horizontalSpacing=”0dp” android:stretchMode=”columnWidth” … Read more

GridLayout (not GridView) how to stretch all children evenly

Starting in API 21 the notion of weight was added to GridLayout. To support older android devices, you can use the GridLayout from the v7 support library. The following XML gives an example of how you can use weights to fill the screen width. <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.GridLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:grid=”http://schemas.android.com/apk/res-auto” android:id=”@+id/choice_grid” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:layout_centerHorizontal=”true” android:padding=”4dp” … Read more