Home:ALL Converter>Make cardview equal in Tablelayout

Make cardview equal in Tablelayout

Ask Time:2018-09-21T17:32:45         Author:matan

Json Formatter

I wrote cardview style in xml. I use Tablelayout and when I put the cardview style- 3 times, the center cardview its not equal to other cardview.I make them equal to each other. What I need to change in the code or add to make the cardview equal?

This is the code:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/simpleTableLayout"
    android:layout_width="match_parent"
    android:background="#ffffff"
    android:layout_height="match_parent"
    android:stretchColumns="1"> <!-- stretch the second column of the layout-->

    <!-- first row of the table layout-->


<TableRow>
    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cardview_id1"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:cardview="http://schemas.android.com/apk/res-auto"
        android:layout_margin="5dp"
        cardview:cardCornerRadius="4dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageButton
                android:id="@+id/finger"
                android:layout_width="120dp"
                android:layout_height="160dp"
                android:background="@drawable/gradient_fingerprint"
                android:onClick="Move_fingerprint"
                android:src="@drawable/fingerprint_64" />

            <TextView
                android:id="@+id/book_title_id1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:onClick="Move_fingerprint"
                android:text="Book Title"
                android:textColor="#2d2d2d"
                android:textSize="13sp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>


    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cardview_id2"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:cardview="http://schemas.android.com/apk/res-auto"
        android:layout_margin="5dp"
        cardview:cardCornerRadius="4dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageButton
                android:id="@+id/finger2"
                android:layout_width="120dp"
                android:layout_height="160dp"
                android:background="@drawable/gradient_fingerprint"
                android:onClick="Move_fingerprint"
                android:src="@drawable/fingerprint_64" />

            <TextView
                android:id="@+id/book_title_id2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:onClick="Move_fingerprint"
                android:text="Book Title"
                android:textColor="#2d2d2d"
                android:textSize="13sp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>


    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cardview_id3"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:cardview="http://schemas.android.com/apk/res-auto"
        android:layout_margin="5dp"
        cardview:cardCornerRadius="4dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageButton
                android:id="@+id/finger3"
                android:layout_width="120dp"
                android:layout_height="160dp"
                android:background="@drawable/gradient_fingerprint"
                android:onClick="Move_fingerprint"
                android:src="@drawable/fingerprint_64" />

            <TextView
                android:id="@+id/book_title_id3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:onClick="Move_fingerprint"
                android:text="Book Title"
                android:textColor="#2d2d2d"
                android:textSize="13sp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>








</TableRow>
</TableLayout>

Its look like this:

example image

Author:matan,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52440730/make-cardview-equal-in-tablelayout
yy