Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align the text to the center of the spinner

How to align the text to the center of the spinner?

enter image description here

code that I am using:

    <Spinner android:id="@+id/s_change_type"
         android:layout_width="match_parent"
         android:layout_gravity="center"
         android:gravity="center"
         android:textAlignment="center"
         style="@style/Spinner"
         android:layout_height="wrap_content"/>

Spinner:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/text1"
      android:singleLine="true"
      style="?android:attr/spinnerItemStyle"
      android:gravity="center"
      android:layout_gravity="center"
      android:layout_width="wrap_content"
      android:textAlignment="inherit"
      android:padding="10dp"
      android:layout_margin="5dp"
      android:layout_height="wrap_content"
      android:ellipsize="marquee"/>

Style used by spinner:

   <style name="Spinner"
       parent="Widget.AppCompat.Spinner.Underlined">
    <item name="android:textColor">@color/color_text</item>
    <item name="android:textSize">12sp</item>
    <item name="android:paddingLeft">@dimen/margin_general_left</item>
    <item name="android:paddingRight">@dimen/margin_general_right</item>
</style>

Thanks

like image 323
Pedro Simões Avatar asked Oct 11 '17 13:10

Pedro Simões


People also ask

How do you center text in HTML?

One way to center text or put it in the middle of the page is to enclose it within <center></center> tags. Inserting this text within HTML code would yield the following result: Center this text!

How do you center align headers in HTML?

To set the heading alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <h1> to <h6> tag, with the CSS property text-align.


1 Answers

In your TextView write:

android:layout_width="match_parent"

Instead of:

android:layout_width="wrap_content"
like image 139
Boukharist Avatar answered Sep 21 '22 14:09

Boukharist