Spinner dropdown height to match parent
Asked Answered
G

6

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

Grandniece answered 16/11, 2015 at 6:24 Comment(3)
it means you doesnt scroll it?Doodlebug
have you tried custom spinner??Cleaves
I think you should go with, Button in place of Spinner, and Use Custom AlertDialog with Layout fill parent to Show your Spinner Items.. i think it may help You.Exactitude
A
1

try using this with your adapter.

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Attraction answered 26/11, 2015 at 10:41 Comment(0)
L
1

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

Labuan answered 27/11, 2015 at 14:20 Comment(0)
C
-1

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

<TextView 

     android:id="@+id/textViewRowFacility"
     android:minHeight="50dp" />
Cleaves answered 16/11, 2015 at 6:32 Comment(0)
E
-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>
Edmondo answered 16/11, 2015 at 6:36 Comment(0)
N
-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?

Now answered 16/11, 2015 at 6:55 Comment(2)
yeah but i have other views in my layoutGrandniece
and i want the dropdown box to only fit the whole screen and not the entire spinner itselfGrandniece
A
-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;
    }
};
Attraction answered 26/11, 2015 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.