2016-06-28 2 views
0

내 안드로이드 응용 프로그램에서 다음과 같은 레이아웃을 만들기 위해 노력하고 여러 ImageButtons 정렬 :안드로이드 - RelativeLayout의

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".MainActivity"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@color/colorPrimary" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" /> 

</LinearLayout> 

:

enter image description here

나는 두 개의 별도의 레이아웃을하려면이 코드를 아래쪽 레이아웃은 ImageButton과 함께 여러 페이지가 있기 때문에 ViewPager이됩니다. 제 질문은 어떻게 각 레이아웃/단편에서 버튼을 완벽하게 정렬 할 수 있습니까?

답변

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:orientation="horizontal"> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:orientation="horizontal"> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

     </LinearLayout> 


    </LinearLayout> 

</LinearLayout>  

중첩 된 레이아웃이 성능에 좋지 않더라도이 유형의 중첩이 최소화되어 있기 때문에 성능 차이는 무시해도 좋습니다.

관련 문제