Spinner tab size

北慕城南 提交于 2019-12-08 07:39:19

问题


I have spinner on my app and I want to make the spaces between each line larger. I have already tried android:TextSize:"30sp" with no luck any ideas?


回答1:


While Creating Adapter for your Spinner give custom layout instead of predefined one

Create xml named spinner_row.xml (Any name of your choice) in res/layout folder

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/cust_view"  
    android:layout_width="match_parent" 
    android:textColor="@color/black"
    android:textSize="32sp"
    android:layout_height="36dp" 
    android:gravity="left|center_vertical"/> 

Here you can change the color Text size and width ,height and spacing by setitng the margin and padding of the Elements in the spinner by modifying this textview

Use it like this while creating Adapter

 ArrayAdapter<String> adapter=new ArrayAdapter<String>(context, R.layout.spinner_row,yourlist);

The Last task is routine

spinner.setAdapter(adapter);

I hope this will help you.


second way,

create a style like this withe attributes of your choice, like test size, padding etc And your style should have a parent parent="@android:style/Widget.TextView.SpinnerItem" as shown in the below style

<style name="spinnerStyleView"  parent="@android:style/Widget.TextView.SpinnerItem">
        <item name="android:background"> @drawable/notetvbg</item>
          <item name="android:textColor">@android:color/darker_gray</item>
    </style>

And apply style to your spinner by using style attribue

 style="@style/spinnerStyleView"



回答2:


If you are using an ArrayAdapter to provide items for the spinner, you would've specified a resource file for the drop down view, maybe android.R.layout.simple_spinner_dropdown_item ?

You could create your own drop down resource and set the height to whatever you want, then pass that to the adapter instead of android.R.layout.simple_spinner_dropdown_item



来源:https://stackoverflow.com/questions/15556321/spinner-tab-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!