2012-08-10 4 views
2

가능한 중복 :
How do I center text horizontally and vertical in a TextView in Android?텍스트 뷰의 중앙에 텍스트를 설정하는 방법

나는 수직 및 수평 텍스트 뷰의 중심에있는 텍스트를 설정합니다. 텍스트를 가로로 가운데에 세로로 배치하면 텍스트 위쪽에 더 많은 공간이 있습니다.

XML 레이아웃 :

<TextView 
     android:id="@+id/txtQuantity" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center|center_vertical" 
     android:text="+" 
     android:textColor="@color/white" 
     android:textSize="25sp" /> 
</LinearLayout> 
+0

<텍스트 뷰 안드로이드 : layout_width = "match_parent" 안드로이드 : layout_height = "match_parent" 안드로이드 : 중력 = "센터" 안드로이드 : 텍스트 = "안녕하세요 Android 개발자 AM" /> – Debasish

답변

5

사용 android:gravity="center" 대신 android:gravity="center|center_vertical".

가로 세로로 가운데에 배치됩니다.

+3

당신이 아래로 투표하면, 투표를 한 이유를 게시하는 것은 큰 도움이됩니다. – prolink007

관련 문제