Reputation: 6114
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
Upvotes: 1
Views: 8886
Reputation: 6114
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
Upvotes: 4
Reputation: 891
Have a layout like relative layout as the main child of the CardView and then have the ImageView the child view of the layout. Then set the ImageView's width and height to match_parent.
You could also alternatively have a framelayout as the main child of the CardView and set its background to the image. Will stretch it up to fill the Card.
Upvotes: 0