João Elvas
João Elvas

Reputation: 113

Cardview size on Android

So what I wanna do is to have a recycler view with images inside each card.

How can I know the width of each card so I can pass the images to the adapter with the exact size and take the entire space of the card? (I want the images to have all the same size.)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card_view:cardCornerRadius="4dp"
    android:layout_margin="5dp">

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


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:id="@+id/phone_card_imageView"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"/>


    </RelativeLayout>
</android.support.v7.widget.CardView>

This is the code I have on the cardview.

Upvotes: 1

Views: 11655

Answers (1)

Guillaume Imbert
Guillaume Imbert

Reputation: 496

Change layout_width and layout_height to fixed size in dp for your ImageView, that will do the trick. Note that you can also fix only the height, and the width will be the one of the screen.

Upvotes: 4

Related Questions