Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why not just check the position of the item relative to the size of your list:</p> <p>Padding:</p> <pre><code> public View getView(int position, View convertView, ViewGroup parent) { //recycle views and whatever else you normally would do goes here.. //... //... if (position == 0){ convertView.setPadding(0, 10, 0, 0); //padding on top for top item } else if (position == getCount() - 1){ convertView.setPadding(0, 0, 0, 10); //padding on bottom for bottom item } else{ convertView.setPadding(0, 0, 0, 0); //no padding } } </code></pre> <p>For margins use </p> <pre><code>LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(left, top, right, bottom); convertView.setLayoutParams(lp); </code></pre> <p>Ex:</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { //recycle views and whatever else you normally would do goes here.. //... //... LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (position == 0){ lp.setMargins(0, 10, 0, 0); //margin on top for top item } else if (position == getCount() - 1){ lp.setMargins(0, 10, 0, 10); //margin on bottom for bottom item } else{ lp.setMargins(0, 0, 0, 0); //no margin } convertView.setLayoutParams(lp); } </code></pre> <p>this is provided you've implemented the getCount() method properly for your adapter. </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