Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here are some examples of borders in a GridView. </p> <p><img src="https://i.stack.imgur.com/p3kpI.png" alt="GridView Borders"></p> <p>You can see where I defined the Red and Blue borders in my XML.</p> <p>This is my main.xml Layout:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/red" &gt; &lt;GridView android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dp" android:background="@color/blue" android:columnWidth="90dp" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="10dp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The thickness of the Red border is controlled GridView's <code>layout_margin</code> attribute and the Blue borders are controlled by <code>horizontalSpacing</code> and <code>verticalSpacing</code>.</p> <p>To make the black cell backgrounds I used this layout and saved it as list_item.xml:</p> <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/black" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" android:paddingLeft="6dip" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; </code></pre> <p>My Activity:</p> <pre><code>public class Example extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] array = new String[] {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"}; List&lt;String&gt; list = new ArrayList&lt;String&gt;(Arrays.asList(array)); GridView grid = (GridView) findViewById(R.id.gridview); grid.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, list)); } } </code></pre>
 

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