12

I have been diving into the world of Android Spinner controls recently and ran into a small issue. I need to align the left side of the drop down with the very far left of the main spinner control. I have tried using dropDownHorizontalOffset to align them and no matter what value I use the horizontal position of the drop down doesn't change, but when I test with dropDownVerticleOffset the vertical position of the drop down does change.

Has anyone worked with those values or might have any idea of how else I could go about aligning them?

Thanks!

user3261293
  • 161
  • 1
  • 6

5 Answers5

4

Solved: I tried the suggested padding change instead of dropDownHorizontalOffset and it did work, the problem was that it also changed the position of the text in the primary spinner object which made it look not so great. So that method does work but is not preferable.

The problem was that we were using a pre 4.1 overall theme for our application (theme.NoTitleBar) and dropDownHorizontalOffset was not supported with that old of a theme because spinners in general were not fully supported then. I changed it to Theme.Holo.Light.NoTitleBar and everything worked fine! I don't think this is too common of an issue but hopefully it can help someone.

user3261293
  • 161
  • 1
  • 6
1

I accomplished the same objective by removing the background of the popup.

spinner.setPopupBackgroundDrawable(null);

That code will remove the background, (and the padding that's coming with it), and therefore will position your dropdown aligned with the spinner.

Obviously, you will need to use your own drawable instead if you don't want it to be transparent.

csalazar
  • 748
  • 1
  • 7
  • 13
1

I think this will work for you:

spinner.setPopupBackgroundDrawable(null);
Severin
  • 8,508
  • 14
  • 68
  • 117
Ali Tariq
  • 28
  • 1
  • 7
0

I have been looking for the latest answer to this question. In case dropDownHorizontalOffset doesn't work or you can't find it. There is an alternative. Set height of the Spinner to 0dp and set marginTop value for vertical Offset and marginRight for horizontal offset.

In my case :

<Spinner
    android:id="@+id/spinner"
    android:background="@null"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginTop="40dp"
    android:layout_marginRight="27dp"
    android:layout_alignParentEnd="true" />

Preview

Mirwise Khan
  • 1,317
  • 17
  • 25
-4

Try using android:paddingLeft instead of dropDownHorizontalOffset

michal.luszczuk
  • 2,883
  • 1
  • 15
  • 22