Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ListViews (along with Fragments, ListFragments, etc) appear to override the provided layout's root parameters (height, width), in order to fit the predefined View/Item dimensions into the parent. This also seems to happen with each of the layout's children Maximum dimensions, for instance, the TextView from AOSP's simple_list_item_1.xml</p> <p>Since you are asking specifically for ListView item spacing, I would still not use dividerHeight as suggested by blackbelt, as this would change the centering of your original content (also the first item would not have the desired spacing from the top of the list, as the divider is below each item).</p> <p>For ListView items, you can generally override this behavior by setting a custom layout (called by a custom adapter) with a top and bottom <strong>margin</strong>. See the following sample based simple_list_item_1.xml and note the margin modifiers at the end:</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:textAppearance="?android:attr/textAppearanceListItemSmall" android:gravity="center_vertical" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:layout_marginTop="20dp" android:layout_marginBottom="20dp" /&gt; </code></pre> <p>(you might need to provide inline values for non-public references to "?android:attr")</p> <p>You would then have to call a custom adapter for your list (such as ArrayAdapter) and supply it with your custom list item XML.</p>
 

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