GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

TableLayout com celulas do mesmo tamanho

xml
Tags: #<Tag:0x00007fc6d875a890>

#1

Tem como forçar as celulas do TableLayoutu ter o mesmo tamanho?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ALunoActivity"
android:padding="8dp">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:stretchColumns="*"
        android:shrinkColumns="*"
        android:orientation="vertical">

        <TableRow

            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <android.support.v7.widget.CardView
                android:id="@+id/cardPerfil"
                android:paddingTop="16dp"
                android:paddingBottom="16dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_marginTop="6dp"
                app:cardElevation="3dp"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="false"
                card_view:cardCornerRadius="2dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:paddingTop="16dp"
                    android:paddingBottom="16dp">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:contentDescription="Icone de uma pessoa"
                        app:srcCompat="@drawable/ic_person_black_24dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="@string/perfil"
                        android:textSize="16sp"
                        android:textStyle="normal" />
                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:id="@+id/cardBusca"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_marginTop="10dp"
                app:cardElevation="3dp"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="false"
                card_view:cardCornerRadius="2dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:paddingTop="16dp"
                    android:paddingBottom="16dp">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:contentDescription="Icone de uma pessoa"
                        app:srcCompat="@drawable/ic_search_black_24dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="@string/busca"
                        android:textSize="16sp"
                        android:textStyle="normal" />
                </LinearLayout>
            </android.support.v7.widget.CardView>



        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <android.support.v7.widget.CardView
                android:id="@+id/cardTurmas"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_marginTop="6dp"
                android:paddingTop="16dp"
                android:paddingBottom="16dp"
                app:cardElevation="3dp"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="false"
                card_view:cardCornerRadius="2dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:id="@+id/card"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:paddingTop="16dp"
                    android:paddingBottom="16dp">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:contentDescription="Icone de uma pessoa"
                        app:srcCompat="@drawable/ic_school_black_24dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="@string/turmas"
                        android:textSize="16sp"
                        android:textStyle="normal" />
                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:id="@+id/cardConversas"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="6dp"
                android:layout_marginTop="6dp"
                android:paddingTop="16dp"
                android:paddingBottom="16dp"
                app:cardElevation="3dp"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="false"
                card_view:cardCornerRadius="2dp"
                card_view:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:paddingTop="16dp"
                    android:paddingBottom="16dp">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:contentDescription="Icone de uma pessoa"
                        app:srcCompat="@drawable/ic_forum_black_24dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="@string/conversas"
                        android:textSize="16sp"
                        android:textStyle="normal" />
                </LinearLayout>
            </android.support.v7.widget.CardView>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </TableLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

#2

Você pode utilizar a propriedade android:layout_weight=“1” para todas as células.