Center Aligned Button's Text on Left

隐身守侯 提交于 2019-12-08 09:50:30

问题


Even though I made gravity center text is still on left. I assume there must be a method to change text align (I have tried android:textAlignment="center" too)

I've included screenshot below but dont have enough reputation to make show it.

<!-- language: lang-xml-->    
<Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:gravity="center"
                android:text="Button" />

also tried to make it match_parent still the same problem.

EDIT for whole XML

<!-- language: lang-xml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/etCommands"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Type a Command"
        android:password="true" >
    </EditText>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Button" />
    </LinearLayout>

    <TextView
        android:id="@+id/tvResults"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="invalid" />

</LinearLayout>

ScreenShot


回答1:


I had this problem too. Just restart your IDE.




回答2:


Adding android:layout_gravity="center" to the layout for the button and have the width wrap_content should fix it.



来源:https://stackoverflow.com/questions/13660415/center-aligned-buttons-text-on-left

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