Modify the Size of an Android Spinner Drop down part Size?

前端 未结 3 965
栀梦
栀梦 2020-12-19 15:24

how can i modify the size of the dropdown part of the spinner?? do i have to do that in XML or in the code itself?

相关标签:
3条回答
  • 2020-12-19 15:55

    You can not change the size of spinner as it is default widget. But you can make it custom using background image. Here is my code:

    <Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent" 
        android:layout_height="45dp"
        android:drawSelectorOnTop = "true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="20dp"
        android:layout_below="@+id/placeCity"
        android:paddingLeft="5dip"
        android:background="@drawable/myspinner_background"
    />
     <ImageView
           android:id="@+id/imageView1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignRight="@+id/spinner"
           android:layout_alignTop="@+id/spinner"
           android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
           android:src="@drawable/down" />
    

    This is written in XML. And make another file called myspinner_background.xml in drawable folder. Inside that, write this code:

    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
        android:color="#f269be"
        android:width="2dp" />
    <solid
        android:color="#ECC8EC" />
    

    0 讨论(0)
  • 2020-12-19 15:59

    I'm no pro but after thousands of tries, here's the ultimately simple solution... just copy this line in Spinner tag...

    android:dropDownHeight="100dp"    <!--change 100dp to your requirement-->
    

    you can also modify width...

    android:dropDownHeight="100dp"   <!--change 100dp to your requirement-->
    

    This works well with autocompletetextview.

    0 讨论(0)
  • 2020-12-19 16:03

    In xml, I believe you set it with android:dropDownWidth. This worked for me:

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:dropDownWidth="dp_value_you_desire" />
    
    0 讨论(0)
提交回复
热议问题