Cristina
Cristina

Reputation: 387

How to leave the cells with the same height in a gridview?

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

Upvotes: 1

Views: 2411

Answers (2)

Techierj
Techierj

Reputation: 141

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...

Upvotes: 1

Arun Mohan
Arun Mohan

Reputation: 211

In every textview add any one property

android:singleLine="true"
   android:maxLines="1" 

Upvotes: 1

Related Questions