Wednesday, March 28, 2018

Select long text in spinner then create space

Leave a Comment

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 :

4 Answers

Answers 1

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" 

Answers 2

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"                             /> 

Answers 3

The thing is that your textView and spinner shares 50% and 50% of parent view. Better you set weightSum to parent view and allocate more width to spinner. Then you can have one line text in spinner.

<LinearLayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:weightSum="10">              <TextView                 style="@style/TextLabelBookGray"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:layout_gravity="center_vertical"                 android:layout_weight="2.5"                 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="0dp"                 android:layout_height="wrap_content"                 android:layout_gravity="center_vertical"                 android:layout_marginBottom="@dimen/_4sdp"                 android:layout_marginTop="@dimen/_4sdp"                 android:layout_weight="7.5"                 android:entries="@array/us_states"/>          </LinearLayout> 

This is a working example and adjust the weight according to your need.

Answers 4

If you can set your spinner width in fixed side and weight of spinner remove then your problem will solve automatically..buddy..!

            <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="150dp"                     android:layout_height="wrap_content"                     android:layout_gravity="center_vertical"                     android:layout_marginBottom="@dimen/_4sdp"                     android:layout_marginTop="@dimen/_4sdp"                     android:entries="@array/us_states"                     /> 

i hope it can help you..!

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment