2011-10-06 11 views
2

다소 지루한 질문에 대해 미안하지만, "action bar"에 버튼을 배치하려하고 "layout_alignRight"등을 사용하는 데 문제가 있습니다. 달성하고자하는 것은 다음과 같습니다.안드로이드 액션 바 버튼 배열

| [button1] _ _ _ 빈 공간 _ _ _ [button2] [button3] [button4] |

나는 네 개의 버튼이 앉아 있어야 어디 RelativeLayout의이 둘러싸고 있고, 나는 아무 소용이 다음과 같은 코드를 시도했다 :

<RelativeLayout android:id="@+id/actionBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#666666" > 


    <Button android:id="@+id/button1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignLeft="@id/actionBar" 
     android:background="@drawable/buttonImg" /> 


    <Button android:id="@+id/button4" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignRight="@id/actionBar" 
     android:background="@drawable/buttonImg" /> 


    <Button android:id="@+id/button3" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_toLeftOf="@id/button2" 
     android:background="@drawable/buttonImg" /> 


    <Button android:id="@+id/button2" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_toLeftOf="@id/button3" 
     android:background="@drawable/buttonImg" />     


</RelativeLayout> 

버튼은 항상 길 밖으로 뻗어 얻을 것을, 또는 모두에 쌓여 얻을 위로 서로 위로. 누구든지 찾고있는 간격을 달성하는 방법을 알고 있습니까?

감사합니다 !!! 단지 상대 레이아웃을 사용하여

답변

1

, 당신은 가장 왼쪽 버튼을 누른 후 오른쪽 버튼을 고정하고 다른 두 버튼은 오른쪽 버튼의 왼쪽 정렬하기 추가해야합니다 :

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button android:id="@+id/b1" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Button1"></Button> 
    <Button android:id="@+id/b4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:text="Button4"></Button> 
    <Button android:id="@+id/b3" 
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/b4" 
     android:text="Button3"></Button> 
    <Button android:id="@+id/b2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/b3" 
     android:text="Button2"></Button> 
</RelativeLayout> 
+0

너무 감사합니다! 나는 그 구성을 이미 시도 했었다고 맹세 할 수 있었다. .. 고마워. – TomBomb

+0

당신을 진심으로 환영합니다. 상대 레이아웃은 스프링 레이아웃만큼이나 복잡하여 쉽게 잃어 버릴 수 있습니다. –