2017-01-06 2 views
1

6 개의 ImageView 블록이 있습니다. 세로 레이아웃, 2 열 3 행에 들어가기를 원합니다.2 열 3 행 정확한 맞춤, 상대적 레이아웃 (안드로이드)

정확히 6 개가되도록 블록을 균등하게 분산 시키려면 어떻게해야합니까?

마지막 네 블록 사이에 약간의 겹침이 있습니다.

은 (이미지 뷰 3-6은 기본적으로 처음 두 동일합니다.)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:id="@+id/imageView" 
    android:padding="96dp" 
    android:background="@color/colorAccent" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/imageView" 
    android:layout_alignParentRight="true" 
    android:id="@+id/imageView2" 
    android:background="@color/colorPrimary" 
    android:padding="96dp" /> 

<ImageView 
    3 /> 

<ImageView 
    4 /> 

<ImageView 
    5 /> 

<ImageView 
    6 /> 

</RelativeLayout> 

답변

1

사용의 LinearLayout. 이미지가 부모를 채우게하려면 ImageView에서 android:scaleType="fitXY"을 사용할 수 있습니다. 참조 용으로 ImageView.ScaleType을보십시오.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 

</LinearLayout> 
+0

감사합니다,이 일! – Edwin

1

이 코드를보십시오 :

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="2" 
android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:weightSum="3" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher"/> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher"/> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@mipmap/ic_launcher"/> 
    </LinearLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:weightSum="3" 
    android:orientation="horizontal"> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:scaleType="fitXY" 
     android:src="@mipmap/ic_launcher"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:scaleType="fitXY" 
     android:src="@mipmap/ic_launcher"/> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:scaleType="fitXY" 
     android:src="@mipmap/ic_launcher"/> 
</LinearLayout>