1

I have a gridview and I need the cells of the same row to have the same height (the Width the Android itself leaves the same, but the height does not), they look like in the image below enter image description here

Ok, every cell has a button and a textview, the textview text can be small or large, and this ends up leaving the height of each cell different. Is there any way to leave all the cells of the same line with the height of the largest cell? It is weird each cell with a different height.

gridview

<GridView
        android:id="@+id/grid_sons"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:horizontalSpacing="3dp"
        android:numColumns="2"
        android:verticalSpacing="3dp" />

cell layout

<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:ignore="ContentDescription">

    <ImageButton
        android:id="@+id/btn"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dp"
        android:background="@color/transparente"
        android:src="@drawable/ic" />

    <TextView
        android:id="@+id/txt_label_cell"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="10dp"
        android:layout_marginEnd="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginStart="5dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/test"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/labelColor" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginEnd="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginStart="10dp"
        android:background="#60ffffff" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/btn_what"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="@color/transparente"
            android:src="@drawable/ic_what" />

        <ImageButton
            android:id="@+id/btn_config"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:background="@color/transparente"
            android:src="@drawable/ic_config" />
    </LinearLayout>
</LinearLayout>

Thx

Cristina
  • 387
  • 1
  • 18

2 Answers2

1

In every textview add any one property

android:singleLine="true"
   android:maxLines="1" 
Arun Mohan
  • 211
  • 3
  • 12
  • Thx, this work. Actually I needed 2 lines then I did this `android:maxLines="2"` and in the end of each text I put a \n, this way, my 1 lines texts had 2, and my more than 2 lines text had just 2 too. This way every cell stay with the same height. – Cristina Mar 20 '17 at 19:41
1

Answer is already given...

Take a look at this post...

GridView rows overlapping: how to make row height fit the tallest item?

I hope this will help you...

Community
  • 1
  • 1
Techierj
  • 131
  • 9