Android Spinner dropDownHorizontalOffset is not working, but dropDownVerticleOffest is

I recently plunged into the Android Spinner world and ran into a small problem. I need to align the left side of the drop down from the farthest left corner of the main spinner control. I tried using dropDownHorizontalOffset to align them, and no matter what value I use, the horizontal position of the dropdown value does not change, but when I test with dropDownVerticleOffset, the vertical position of the dropdown value changes.

Has anyone worked with these values ​​or could have any idea of ​​how else I could reconcile them?

Thanks!

+7
java android spinner dropdownbox
source share
5 answers

Solved: I tried the proposed change of add-ons instead of dropDownHorizontalOffset, and it really worked, the problem was that it also changed the position of the text in the primary spinner's object, which made it look not very large. Thus, this method works, but is not preferred.

The problem was that we used a common theme up to 4.1 for our application (theme.NoTitleBar), and dropDownHorizontalOffset was not supported by this old theme, because in general, fully supportive players were not supported. I changed it to Theme.Holo.Light.NoTitleBar and everything worked out fine! I don't think this is too common in the problem, but hopefully this can help someone.

+3
source share

I achieved the same goal by removing the pop-up background.

spinner.setPopupBackgroundDrawable(null); 

This code will remove the background (and the add that will come with it), and therefore will display the drop-down list aligned with a counter.

Obviously, you will need to use your own drawable if you do not want it to be transparent.

+1
source share

I think this will work for you:

 spinner.setPopupBackgroundDrawable(null); 
+1
source share

I was looking for the last answer to this question. In case dropDownHorizontalOffset does not work, or you cannot find it. There is an alternative. Set the height from Spinner to 0dp and set marginTop 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

0
source share

Try using android:paddingLeft instead of dropDownHorizontalOffset

-3
source share

All Articles