Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate android spinner dropdown window

Tags:

android

I am trying to achieve a vertical Spinner. I am able to rotate the spinner view using

 spinner.setRotation(-90);

But this rotates only spinner view but not the dropdown list. As shown in the below image. How to rotate dropdown window also?

enter image description here

After trying below answer I am getting into this problem

enter image description here


1 Answers

You will need to create a custom adapter for your spinner.

Next on your getView make sure you rotate the parent that get's passed to it.

An example adapter:

public class AdapterTest extends ArrayAdapter<String> {


    public AdapterTest(Context context, int resource, List<String> objects) {
        super(context, resource, objects);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = LayoutInflater.from(getContext()).inflate(R.layout.row_spinner, parent, false);
        if (parent.getRotation() == 0 && parent instanceof ListView) {
             parent.setRotation(-90);
        }
        return v;
    }
}

Result:

enter image description here

like image 144
Pedro Oliveira Avatar answered Jan 06 '26 03:01

Pedro Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!