Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select long text in spinner then create space

when i select long text in my spinner then its create space between textView and spinner

see my default spinner :

enter image description here

after selecting a long text it's look like below shot:

enter image description here

below is xml code :

<TextView
                    style="@style/TextLabelBookGray"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="@string/hint_state"
                    android:textSize="@dimen/_14ssp"
                    android:paddingLeft="@dimen/_2sdp"
                    android:visibility="visible" />

                <android.support.v7.widget.AppCompatSpinner
                    android:id="@+id/spStates"
                    style="@style/TextLabelBookBlack"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginBottom="@dimen/_4sdp"
                    android:layout_marginTop="@dimen/_4sdp"
                    android:layout_weight="1"
                    android:entries="@array/us_states"
                    />

below code is style.xml:

<style name="TextLabelBookGray" parent="FontBook">
        <item name="android:textSize">@dimen/_14ssp</item>
        <item name="android:textColor">@color/input_color_gray</item>

any one have any idea how to i fix it

Thanks in advance :

like image 968
Ali Avatar asked Feb 16 '18 11:02

Ali


2 Answers

You set spinner height as "wrap_content" so it will automatically adjust its height.You should set Spinner row's Textview max line as 1.Then it will not show double line. Textview xml file

android:maxLines="1"
like image 93
Kush Avatar answered Sep 22 '22 14:09

Kush


Adding to @Kush answer, Please make sure that your parent also having wrap_content so that your spinner text can show in one line. Otherwise, It will look same even if you give wrap_content to your spinner.

Please use below code:

  <android.support.v7.widget.AppCompatSpinner
                            android:id="@+id/spStates"
                            style="@style/TextLabelBookBlack"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_marginBottom="@dimen/_4sdp"
                            android:layout_marginTop="@dimen/_4sdp"
                            android:layout_weight="1"
                            android:maxLines="1"
                            android:entries="@array/us_states"
                            />
like image 31
Jitesh Mohite Avatar answered Sep 20 '22 14:09

Jitesh Mohite