2012-09-21 6 views
0

LinearLayout의 가운데에 텍스트를 가로로 놓는 방법은 무엇입니까? layout_margin을 사용해야합니까?LinearLayout의 가운데에 텍스트를 가로로 놓는 방법은 무엇입니까?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello" 
    android:layout_gravity="center_horizontal" // this does not work 
/> 
</LinearLayout> 

답변

0

을 사용해야합니다.

<LinearLayout> 
      android:gravity="center_horizontal" 
    </LinearLayout> 

그렇지 않으면 아래와 같은 TextView을 변경

<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Hello" 
android:gravity="center_horizontal" 
/> 
+0

나는 내 질문을 너무 많이 단순화했다. – user1301568

1

당신은 당신의 LinearLayout에이 속성을 추가 gravity 대신 layout_gravity

+0

그 중 하나가 작동하지 않습니다. fill_parent 너비를 변경하면 작동합니다. 나는 진짜 프로젝트에서 그렇게 할 수 없다. – user1301568

+0

그러면 패딩을 시도해 볼 수 있습니다. 왜 "fill_parent"에서 그것을 바꿀 수 없습니까? – Blackbelt

관련 문제