add Padding To ListView - Android android.widget

Android examples for android.widget:ListView

Description

add Padding To ListView

Demo Code

import android.view.View;
import android.widget.ListView;

public class Main {

  private static final double TEXT_LEFT_PADDING_TO_CARD_PADDING_RATIO = 1.1;

   static void addPaddingToView(ListView listView, int parentWidth, int listSpaceWeight, int listViewWeight) {
    if (listSpaceWeight > 0 && listViewWeight > 0) {
      double paddingPercent = (double) listSpaceWeight / (double) (listSpaceWeight * 2 + listViewWeight);
      listView.setPadding((int) (parentWidth * paddingPercent * TEXT_LEFT_PADDING_TO_CARD_PADDING_RATIO),
          listView.getPaddingTop(), (int) (parentWidth * paddingPercent * TEXT_LEFT_PADDING_TO_CARD_PADDING_RATIO),
          listView.getPaddingBottom());// w w w.j a v  a2s  . c o  m

      listView.setClipToPadding(false);
      listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    }
  }

}

Related Tutorials