2012-12-01 42 views
0

即使我让重心文字仍然在左边。我假设必须有一种方法来改变文本对齐 (我也尝试过android:textAlignment =“中心”太)左边的中心对齐按钮文字

我已经包括下面的屏幕截图,但没有足够的声望来显示它。

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

也试图让它匹配_parent仍然是同样的问题。

EDIT对于整个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

+0

它的默认居中。 – Ahmad

+0

是的,我知道这意味着我尝试过。 –

+0

只要删除'android:gravity =“center”' – Ahmad

回答

25

我也有这个问题。只需重新启动您的IDE。

+0

你也救了我! :)这工程.. :) –

+0

救生答案! – FOliveira

+0

重新启动IDE适用于我。希望Eclipse中有刷新或重新呈现按钮 – fedmich

0

添加机器人:layout_gravity = “中心” 的布局为按钮,并具有宽度WRAP_CONTENT应该修复它。

+0

它没有修复我的问题。 –

+0

是的,我很抱歉,我刚刚意识到你是在谈论文本而不是实际的按钮。我应该仔细阅读。会看起来更多一点 – codeMagic

+0

你想让文字“按钮”居中?因为它看起来像是在我的屏幕截图上,当我复制代码并运行它时 – codeMagic