Android Spinner dropDownHorizontalOffset not functioning but dropDownVerticleOffest is
Asked Answered
L

5

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!

Liston answered 1/2, 2014 at 20:20 Comment(2)
There's a bug: code.google.com/p/android/issues/detail?id=70754Bandur
Did you find a solution to this problem? The bug report is marked obsolete yet I just faced with this problem. Amazing :)Spacious
L
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.

Liston answered 24/3, 2014 at 14:28 Comment(0)
G
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.

Gadmann answered 8/7, 2014 at 0:43 Comment(0)
S
1

I think this will work for you:

spinner.setPopupBackgroundDrawable(null);
Scriber answered 10/10, 2014 at 6:55 Comment(0)
A
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

Aerophyte answered 28/9, 2017 at 17:30 Comment(0)
D
-4

Try using android:paddingLeft instead of dropDownHorizontalOffset

Durance answered 1/2, 2014 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.