8

Is it possible to adjust height of Spinner dropdown to fill the entire screen. Right now i have 3 items that i dynamically add into the spinner adapter but these only cover half of the screen. What i have right now is something like this:

enter image description here

What i want is something like this:

enter image description here

I could add empty items but that won't solve the problem for different screen sizes

I tried to implement a style on the spinner but it didn't work

<style name="MyCustomSpinner" parent="Widget.AppCompat.Spinner.DropDown">
    <item name="android:dropDownHeight">match_parent</item>
</style>

UPDATE

I have a view between action bar and spinner so i cannot use layout_weight=1 for my spinner

stud91
  • 1,854
  • 6
  • 31
  • 56

6 Answers6

1

try using this with your adapter.

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Syed Arsalan Kazmi
  • 949
  • 1
  • 11
  • 17
1

The only way to achieve this is by writing your own view that works like a spinner.

EmptyCup
  • 421
  • 4
  • 14
-1

In yourspinner.xml, add the android:minHeight="48dp" to TextView element. see the example below-

<TextView 

     android:id="@+id/textViewRowFacility"
     android:minHeight="50dp" />
sud
  • 505
  • 1
  • 4
  • 12
-1

Try to put your Spinner in LinearLayout & set spinner weight to 1 like

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

    </LinearLayout>
Divyang Panchal
  • 1,889
  • 1
  • 19
  • 27
-1

Set the weight of the spinner to take the entire space. If no other view is there in the Layout then use this code:

<Spinner

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

To learn more about android weight refer to this:

What does android:layout_weight mean?

Community
  • 1
  • 1
-1

Try using the code below

ArrayAdapter<String> yourSpinnerAdapter = new ArrayAdapter<String>(this,
            R.layout.spinner_item, yourItem) {

    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
        convertView = super.getDropDownView(position, convertView,
                parent);

        convertView.setVisibility(View.VISIBLE);
        ViewGroup.LayoutParams p = convertView.getLayoutParams();
        p.height = 100; // assign the required height here
        convertView.setLayoutParams(p);

        return convertView;
    }
};
Syed Arsalan Kazmi
  • 949
  • 1
  • 11
  • 17