Thank you all for answers. The answer of matthias lead me to the following solution that worked like a charm:
public class ZeroPaddingArrayAdapter<T> extends ArrayAdapter<T> {
public InboxTypeAdapter(Context context, int textViewResourceId, T[] objects) {
super(context, textViewResourceId, objects);
}
public static ArrayAdapter<CharSequence> createFromResource(Context context,
int textArrayResId, int textViewResId) {
CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
return new ZeroPaddingArrayAdapter<CharSequence>(context, textViewResId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setPadding(
0,
view.getPaddingTop(),
0,
view.getPaddingBottom()
);
return view;
}
}
For spinners:
getView()
- Get the view of the currently selected item.
getDropDownView()
- Get the views that are displayed when spinner is open.
We only need to reduce the padding in getView()
.
Just use this adapter instead of the simple ArrayAdapter
.