How to change popup gravity of a spinner dropdown in android

50 Views Asked by At

I am currently developing a mobile application where I have to use a spinner. More formally I am using androidx.appcompat.widget.AppCompatSpinner. The spinner has this following options:

<androidx.appcompat.widget.AppCompatSpinner
    android:id="@+id/my_spinner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" />

The spinner is positioned to the right side of the screen. The drop down dialog of this spinner seems to be anchored with the left side of my_spinner. So the dialog's left side is aligned with the left side of my_spinner. But I want to align the dialog/drop-down's right side with my_spinner's right side. How can I achieve that?

I tried creating my custom adapter and overriding the getDropDownView and tried adding different types of gravity values. But that didn't seem to work in any way. Then I also tried adding margin to the view. But margin's do not work in popup views.

0

There are 0 best solutions below