2012-12-01 7 views
0

중력 중심 텍스트를 만들었지 만 여전히 왼쪽에 있습니다. 텍스트 정렬을 변경하는 방법이 있어야한다고 가정합니다. (나는 android : textAlignment = "center"도 시도했습니다.)가운데 맞춤 단추의 텍스트

아래 스크린 샷을 포함 시켰지만 표시 할만한 평판은 충분하지 않습니다.

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

또한 동일한 문제로 match_parent를 만들려고했습니다. 전체 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를 다시 시작하면 문제가 해결됩니다. 이클립스에 새로 고침 버튼이나 리 렌더링 버튼이 있기를 바란다. – fedmich

0

추가 안드로이드

편집 : 버튼의 레이아웃 layout_gravity = "센터"와 폭 wrap_content 그것을 수정해야합니다.

+0

수정되지 않았습니다. 내 문제. –

+0

예, 죄송합니다. 방금 실제 버튼이 아니라 텍스트에 대해 이야기하고 있다는 것을 깨달았습니다. 나는 더 신중하게 읽어야한다. 조금 더 보일 것입니다 – codeMagic

+0

텍스트 "단추"를 가운데로 표시 하시겠습니까? 스크린 샷에 나와있는 것처럼 보이고 코드를 복사하여 실행할 때 – codeMagic