2011-09-25 2 views
0

레이아웃에 3 개의 버튼이있는 활동이 있습니다. 모든 버튼이 하단에 있습니다. 극단적 인 왼쪽, 중앙 및 극한의 오른쪽 버튼을 원했습니다. 극한의 오른쪽과 왼쪽 버튼은 괜찮습니다. 그러나 중앙 버튼은 왼쪽과 오른쪽 버튼 사이의 모든 공간을 차지합니다. 그러나 중간 단추가 모든 공간이 아닌 필요한 공간을 차지하도록합니다. 또한 imageButton을 화면 중간으로 이동할 수 없습니다. 이 일에 어떤 도움이 필요합니까?android의 3 버튼 레이아웃 문제

  <?xml version="1.0" encoding="utf-8"?> 

      <RelativeLayout 
      android:id="@+id/rel" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/backgroundnr" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      > 

      <ImageButton 
      android:id="@+id/imageButtons" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/tempText2" 
      android:layout_above="@+id/tempText" 
      android:gravity="center" 
      android:src="@drawable/start" 
      android:background="@null" 
      android:layout_gravity="center_horizontal" 
      > 
      </ImageButton> 

      <TextView 
      android:id="@+id/tempText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Touch to Start" 
      android:layout_centerVertical="true" 
      android:layout_gravity="center_vertical" 
      > 
      </TextView> 

      <ImageView 
      android:id="@+id/bottomlayout" 
      android:layout_width="fill_parent" 
      android:layout_height="100px" 
      android:src="@drawable/bottombar" 
      android:layout_alignParentBottom="true" 
      > 
      </ImageView> 

      <Button 
      android:id="@+id/profileButtons" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Profile" 
      android:drawableTop="@drawable/profiledefault" 
      android:gravity = "bottom" 
      android:background="#0000" 
      android:layout_alignParentBottom="true" 
      android:layout_alignLeft="@+id/bottomlayout" 
      android:textColor="#FFFFFF" 
      android:paddingLeft="10dip" 
      android:paddingBottom="5dip" 
      > 
      </Button> 
      <Button 
      android:id="@+id/savedButtons" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Saved" 
      android:drawableTop="@drawable/favoritesdefault" 
      android:gravity = "bottom" 
      android:background="#0000" 
      android:layout_alignParentBottom="true" 
      android:textColor="#FFFFFF" 
      android:paddingBottom="5dip" 
      android:layout_toRightOf="@+id/profileButtons" 
      android:layout_toLeftOf="@+id/recentButtons" 
      android:layout_gravity="center_horizontal" 
      > 
      </Button> 
      <Button 
      android:id="@+id/recentButtons" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Recent" 
      android:drawableTop="@drawable/recentdefault" 
      android:gravity = "bottom" 
      android:background="#0000" 
      android:layout_alignParentBottom="true" 
      android:textColor="#FFFFFF" 
      android:layout_alignParentRight="true" 
      android:paddingRight="10dip" 
      android:paddingBottom="5dip" 
      > 
      </Button> 
      </RelativeLayout> 
+0

layout_weight 속성 – Blackbelt

답변

3

사용하여하여 ImageButton 대신 layout_gravity에 대한

android:layout_centerHorizontal="true"

: 여기 내 XML 레이아웃 파일입니다.

하단 버튼을 재정렬하려면 다음을 수행하십시오.

"savedButtons"인 중간 버튼에는 leftOf 또는 rightOf를 사용하지 마십시오. 단지에 대한

android:layout_centerHorizontal="true"

를 사용합니다. 그리고 왼쪽 버튼은 "profileButtons"는 "recentButtons는"이 레이아웃에서

android:layout_toRightOf = "@+id/savedButtons" 

을 사용하여 오른쪽 버튼에 대한

android:layout_toLeftOf = "@+id/savedButtons" 

을 사용하는 가운데 버튼이 필요 중앙 공간을 차지합니다, 그리고 왼쪽과 오른쪽 영역에 남아 나머지 버튼에는 사용됩니다. 3 개의 버튼 각각에 대해 alignParentBottom이 필요합니다.

HTH.

+0

에 감사드립니다. 완전히 일했다. 그냥 부품을 주석 처리하지 않아도됩니다. – ahsan