2013-08-20 3 views
0

im пытается разобраться, как разместить 6 изображений на экране в формации 2X3. Все изображения должны быть квадратными и одинаковыми с небольшим отрывом. Вот то, что я до сих пор, который дает мне это:Android Layout - Spacing 6 images

As you can see the bottom images are squashed

Что происходит от макета:

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

    <!-- Top Row --> 
    <LinearLayout 
     android:baselineAligned="false" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <RelativeLayout 
      android:id="@+id/relative_1" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="3dp" 
      android:layout_marginTop="6dp" 
      android:layout_marginBottom="3dp"> 
      <ImageView 
       android:id="@+id/img_head" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_head" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_head" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_head" 
       android:layout_alignLeft="@id/img_head" 
       android:layout_alignRight="@id/img_head" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_head" 
       /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:id="@+id/relative_2" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="3dp" 
      android:layout_marginRight="6dp" 
      android:layout_marginTop="6dp" 
      android:layout_marginBottom="3dp"> 
      <ImageView 
       android:id="@+id/img_custom1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_custom1" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_custom1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_custom1" 
       android:layout_alignLeft="@id/img_custom1" 
       android:layout_alignRight="@id/img_custom1" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_custom1" 
       /> 
     </RelativeLayout> 
    </LinearLayout> 


    <!-- Second Row --> 
    <LinearLayout 
     android:baselineAligned="false" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <RelativeLayout 
      android:id="@+id/relative_3" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="3dp" 
      android:layout_marginTop="3dp" 
      android:layout_marginBottom="3dp"> 
      <ImageView 
       android:id="@+id/img_custom2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_custom2" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_custom2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_custom2" 
       android:layout_alignLeft="@id/img_custom2" 
       android:layout_alignRight="@id/img_custom2" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_custom2" 
       /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:id="@+id/relative_4" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="3dp" 
      android:layout_marginRight="6dp" 
      android:layout_marginTop="3dp" 
      android:layout_marginBottom="3dp"> 
      <ImageView 
       android:id="@+id/img_custom3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_custom3" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_custom3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_custom3" 
       android:layout_alignLeft="@id/img_custom3" 
       android:layout_alignRight="@id/img_custom3" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_custom3" 
       /> 
     </RelativeLayout> 
    </LinearLayout> 


    <!-- Third Row --> 
    <LinearLayout 
     android:baselineAligned="false" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <RelativeLayout 
      android:id="@+id/relative_5" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="3dp" 
      android:layout_marginTop="3dp" 
      android:layout_marginBottom="6dp"> 
      <ImageView 
       android:id="@+id/img_custom4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_custom4" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_custom4" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_custom4" 
       android:layout_alignLeft="@id/img_custom4" 
       android:layout_alignRight="@id/img_custom4" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_custom4" 
       /> 
     </RelativeLayout> 
     <RelativeLayout 
      android:id="@+id/relative_6" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="3dp" 
      android:layout_marginRight="6dp" 
      android:layout_marginTop="3dp" 
      android:layout_marginBottom="6dp"> 
      <ImageView 
       android:id="@+id/img_custom5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/text_custom5" 
       android:src="@drawable/headlines" 
       android:clickable="true" 
       /> 
      <TextView 
       android:id="@+id/text_custom5" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignTop="@id/img_custom5" 
       android:layout_alignLeft="@id/img_custom5" 
       android:layout_alignRight="@id/img_custom5" 
       android:layout_margin="1dp" 
       android:gravity="center" 
       android:text="@string/text_custom5" 
       /> 
     </RelativeLayout> 
    </LinearLayout> 
</LinearLayout> 

Как вы можете видеть нижние изображения сжато, я попытался с помощью андроид: вес на линейных макетах, но, предположительно, я не могу это использовать. Что мне нужно изменить?

ответ

1

использовать GridView. он позволяет организовать суб-представления в произвольной сетке с высокой степенью настраиваемости.

0

GridView - это ViewGroup, которая отображает элементы в двумерной прокручиваемой сетке. Элементы сетки автоматически вставляются в макет с помощью ListAdapter.