0

I have a fragment with a spinner in a layout. The spinner xml is:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spCategory"
            android:spinnerMode="dialog"
            android:dropDownWidth="match_parent"
            android:prompt="@string/label_category_select" />

Populating the spinner is done like this:

    List<Category> categories = categoryRepository.getAll();
    CategoryAdapter adapter = new CategoryAdapter(this.getActivity(), categories);
    adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    spCategory= (Spinner)view.findViewById(R.id.spCategory);
    spCategory.setAdapter(adapter);

CategoryAdapter extends ArrayAdapter and I use ViewHolder pattern. The adapter uses this custom layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tvSpinnerRowId"
        android:visibility="gone">
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tvSpinnerRowName">
    </TextView>  
</RelativeLayout>

The problem is that the spinner height in the layout extends to the bottom of the screen.

What am I missing?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

2 Answers2

0

After some more research it seems that you can not manipulate the height of the Spinner dropdown, or any other of it's layout attributes.

This is because the dropdown is actually a popup dialog that cannot be accesed from the Spinner View.

This answer states it clear: http://stackoverflow.com/a/1918655/529138

So it seams that I have to use android:layout_marginBottom as specified in the question.

Anil Meenugu
  • 1,411
  • 1
  • 11
  • 16
0

Try modifying the following line in you .xml file

android:dropDownWidth="match_parent"

to

android:dropDownWidth="300dp"

or wrap_content

Hope this should help !

Abhay Kumar
  • 5,048
  • 2
  • 16
  • 21