2017-01-06 12 views
1

私は6つのImageViewブロックを持っています。2列3行完全一致、相対レイアウト(Android)

これらを正確に合わせるにはどのようにして、6つのブロックが均等に分散されるようにしますか。

最後の4つのブロックの間にわずかな重なりがあります。

(ImageViewの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>