How can I limit the height of a Spinner
from the layout
where I have it?
The problem is that on devices with smaller screens it has too much height , so I need to change it from layout
layout
<Spinner
android:id="@+id/spinnerzodiaco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="@drawable/borde_spinner" />
What I want to achieve is this:
That is smaller in height in different layout
, I already know how is the theme of layout
, layout-large
... But I do not know how I can modify the height of Spinner
EDITO1:
Doing so does not work, does not change the height:
clase
spin = (Spinner) findViewById(R.id.spinnerzodiaco);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
// Obtiene la variable mPopup y realiza cast a ListPopupWindow
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spin);
// Define la altura en dimens.xml
popupWindow.setHeight(R.dimen.height_spinner);
}
catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
Log.e("Exception", e.getMessage());
}
dimens.xml
<resources>
...
<dimen name="height_spinner">100dp</dimen>
</resources>
If I do so, yes:
spin = (Spinner) findViewById(R.id.spinnerzodiaco);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
// Obtiene la variable mPopup y realiza cast a ListPopupWindow
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spin);
// Como ejemplo define la altura a 300 pixeles.
popupWindow.setHeight(300);
}
catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
Log.e("Exception", e.getMessage());
}
But I need to have different measurements for each device so I need to use dimens.xml