2013-10-02 3 views
5

Я использую GridView в своем коде. У меня проблема с пространством. Это моя проблема:Пробелы между элементами GridView

enter image description here

Когда текст не коротка, не проблема, но проблема в том, когда больше. Я хочу, чтобы получить это:

enter image description here

Это мой GridView:

<GridView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:divider="@color/transparente" 
      android:horizontalSpacing="4dp" 
      android:longClickable="true" 
      android:numColumns="2" 
      android:scrollbars="none" 
      android:verticalSpacing="4dp" > 
     </GridView> 

И это XML-элементов в GridView:

<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="wrap_content" 
    android:layout_margin="5dp" 
    android:gravity="center_vertical" 
    android:paddingLeft="5dp" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingBottom="5dp" 
     android:paddingTop="2dp" > 

     <TextView 
      android:id="@+id/textView_title_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Text text text text text text" 
      android:textColor="@color/blanco" 
      android:textSize="@dimen/titulos" /> 

     <TextView 
      android:id="@+id/textView_alarm_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Text text text text text text" 
      android:textColor="@color/blanco" 
      android:textSize="@dimen/contenido" /> 

     <TextView 
      android:id="@+id/textView_alarm_days" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Text text text text text text" 
      android:textColor="@color/blanco" 
      android:textSize="@dimen/contenido" /> 
    </LinearLayout> 

</LinearLayout> 

Я пытался использование android: stretchMode = "spacingWidth", "columnWidth" and android: verticalSpacing = "4DP" ... но безуспешно

Я искал ответы, но не могу найти что-нибудь, чтобы помочь мне

Я признателен за любую помощь

Спасибо и привет

+0

что делать, если вы устанавливаете layout_height основного LinearLayout элемента в "match_parent" вместо "wrap_content"? – mihail

+0

Я уже пробовал это изменение, но не работает – Sergio76

ответ

2

Вы должны объявить реальный размер макс. Установка в корневом макете любых параметров не поможет. Вы должны установить его отдельно в каждом из дочерних элементов. Например, вот мой код, пожалуйста, посмотрите на эти два дочерних элемента, они имеют максимальную высоту и ширину. Я думаю, что ширина установки не имеет значения, но я могу ошибаться. Однако размер высоты должен быть установлен в любом случае. Пожалуйста, проверьте это и попробуйте в своем проекте.

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

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="150dp" 
     android:layout_height="200dp" 
     android:src="@drawable/stub" 
     android:scaleType="centerCrop" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="80dp" 
     android:layout_gravity="center_horizontal|center_vertical" 
     android:textSize="20dip" 
     android:ellipsize="end" 
     android:visibility="visible" 
     android:text="text" /> 
</LinearLayout> 
Смежные вопросы