Greater space between spinner items

Asked

Viewed 424 times

0

I’m creating an app that has spinner, but when opening the items are always glued together, I wonder if only by custom spinner I can give space or there is some style/theme that already has these spaces...as class and everything is already created only lack the functional layout when opening the spinner

  • Aleff, how are you assembling the layout of your items? in general just add a padding to give a spacing...

2 answers

1

Create your own Adapter, so you can customize it the way you prefer.

Example:

public class Listadapter extends Arrayadapter {

public ListAdapter(Context context, int textViewResourceId) {
    super(context, R.id.campotexto);
}

public ListAdapter(Context context, int resource, List<Item> items) {
    super(context, resource, items);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;

    if (v == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(R.layout.linhacustomizada, null);
    }

    Item p = getItem(position);

    if (p != null) {
        TextView tt1 = (TextView) v.findViewById(R.id.id);
        TextView tt2 = (TextView) v.findViewById(R.id.categoryId);
        TextView tt3 = (TextView) v.findViewById(R.id.description);

        if (tt1 != null) {
            tt1.setText(p.getId());
        }

        if (tt2 != null) {
            tt2.setText(p.getCategory().getId());
        }

        if (tt3 != null) {
            tt3.setText(p.getDescription());
        }
    }

    return v;
}

}

1


You can change the appearance of your spinner by changing the adapter that was used for it with the following command:

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

The simple_spinner_dropdown_item is the default layout for spinners. I believe this is what you are looking for. If you prefer you can also create a custom style.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.