2011-07-03 4 views
0

6 개의 버튼이 있습니다. XML은 다음과 같습니다. 버튼 텍스트가 가운데에 맞춰지고 크기가 모두 같아 지도록 변경하는 방법?모든 버튼 크기, 가운데 텍스트 (안드로이드)

크기 설정이 트릭을 수행한다고 가정 했습니까?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 


<Button 
android:id="@+id/Button1" 
android.layout_height="100px" 
android.layout_width="60px" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="BUTTON1"/> 

답변

1

당신은

android:layout_width="fill_parent" 

대신 버튼 속성에

android:layout_width="wrap_content" 

의 사용해야합니다. 있는 LinearLayout에 패딩 속성 예 : 버튼의 폭은 안드로이드에 의해 변경 될 수있는 모든 자식의 높이와 layout_weight를위한

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:paddingLeft="10px" 
android:paddingRight="10px" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 


<Button 
android:id="@+id/Button1" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:text="BUTTON1"/> 
2

사용 fill_parent를 = "1", 당신은을 설정하려는 경우가

1

작동합니다 희망 버튼의 텍스트 가운데는 android : gravity = "center_vertical | center_horizontal"속성을 사용합니다.

크기를 사용하려면 android : layout_height = "100px"및 android : layout_width = "60px"속성을 사용하십시오.

이 버튼의 전체 XML 레이아웃입니다 :

 <Button 
android:id="@+id/button" 
android:layout_height="100px" 
android:layout_width="60px" 
android:gravity="center_vertical|center_horizontal" 
android:text="Your text!"/>