Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to take a look at <a href="http://developer.android.com/design/building-blocks/grid-lists.html" rel="nofollow noreferrer">http://developer.android.com/design/building-blocks/grid-lists.html</a>. Not exactly sure what you are trying to do, but I hope this helps. It uses GridView instead of GridLayout. A good post about that can be found <a href="https://stackoverflow.com/questions/11307218/gridview-vs-gridlayout-in-android-apps">GridView VS GridLayout in Android Apps</a></p> <p><strong>Edit:</strong> Here is my example</p> <p><em><strong>Note:</strong></em> Most of this is taken from <a href="http://developer.android.com/guide/topics/ui/layout/gridview.html" rel="nofollow noreferrer">http://developer.android.com/guide/topics/ui/layout/gridview.html</a>. The ImageAdapter used in GridViewExample is taken directly from there as are the pictures used. </p> <p>Here is my layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:textColor="@android:color/black" android:textStyle="bold" android:textSize="50sp" android:gravity="center_horizontal" android:text="Page Title" /&gt; &lt;!-- Insert some sort of scrolling if desired --&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/black" android:textColor="@android:color/white" android:textSize="25sp" android:gravity="center_horizontal" android:text="Grid 1 Title" /&gt; &lt;GridView android:id="@+id/gridView1" android:layout_width="fill_parent" android:layout_height="100dp" android:columnWidth="50dp" android:numColumns="auto_fit" android:verticalSpacing="5dp" android:horizontalSpacing="5dp" android:stretchMode="columnWidth" android:gravity="center" /&gt; &lt;TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/black" android:textColor="@android:color/white" android:textSize="25sp" android:gravity="center_horizontal" android:text="Grid 2 Title" /&gt; &lt;GridView android:id="@+id/gridView2" android:layout_width="fill_parent" android:layout_height="100dp" android:columnWidth="50dp" android:numColumns="auto_fit" android:verticalSpacing="5dp" android:horizontalSpacing="5dp" android:stretchMode="columnWidth" android:gravity="center" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here is my Main Activity:</p> <pre><code>package com.example.gridviewdemo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import android.widget.Toast; public class GridViewExample extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gridview_example); GridView gridView1 = (GridView) findViewById(R.id.gridView1); gridView1.setAdapter(new ImageAdapter(this)); gridView1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { Toast.makeText(GridViewExample.this, "1: " + position, Toast.LENGTH_SHORT).show(); } }); GridView gridView2 = (GridView)findViewById(R.id.gridView2); gridView2.setAdapter(new ImageAdapter(this)); gridView2.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id){ Toast.makeText(GridViewExample.this, "2: " + position, Toast.LENGTH_SHORT).show(); } }); } } </code></pre> <p>Produces: <img src="https://i.stack.imgur.com/Pce6W.png" alt="Image"> It looks like the layout is a little off on a tablet, but with some work I am sure that can be fixed</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload