Issue
I have this cardview with an image but the thing is, the image does not fill the card and I am not sure why this is happening (changing the width does not seem to affect anything).
This is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="130dp"
app:cardCornerRadius="16dp"
app:strokeColor="@color/white">
<ImageView
android:id="@+id/iv_news"
android:layout_width="250dp"
android:layout_height="130dp"
android:layout_marginStart="10dp"
android:background="@drawable/card_background_shape"
android:scaleType="centerCrop" />
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/tv_title"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="@string/news_title"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</LinearLayout>
Solution
You need to remove android:layout_marginStart="10dp"
in your ImageView
.
It only should look like this:
<ImageView
android:id="@+id/iv_news"
android:layout_width="250dp"
android:layout_height="130dp"
android:background="@drawable/card_background_shape"
android:scaleType="centerCrop" />
Result:
Answered By - DEX7RA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.