superman superman - 1 month ago 14
Android Question

how to fit an ImageView inside a CardView

I have a fixed size

CardView
, and I need to fill it with an
ImageView
, this is how the code looks so far:

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card1x"


android:layout_width="160dp"
android:layout_height="170dp">

<ImageView
android:id="@+id/futourImage"

android:src="@drawable/futourfie"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

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


And in order to fit it, tried :

ImageView futour = (ImageView)findViewById(R.id.futourImage);
futour.setScaleType(ImageView.ScaleType.FIT_XY);


But doesn't seems to solve the problem, looking for an effective solution! Thanks

Answer

Fixed it by changing :

ImageView image_id = (ImageView)findViewById(R.id.ImageID);
image_id.setScaleType(ImageView.ScaleType.CENTER_CROP);

and setting :

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

for the ImageView