Reputation: 169
I have an image in the top of a card view. It has a litte (unwanted) margin one the right and I don't know why... Maybe someone can give me a hint how to fix it? Thanks a lot!
If i don't use "adjustViewBounds", it works. But I need it for further views under the image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/nature"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:id="@+id/exercise_picture"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Upvotes: 0
Views: 896
Reputation: 4940
Try setting the ImageView scaleType to something that fills all the provided space such as cropCenter.
fitStart will fit the whole image into the space and preserve the aspect ratio. Since the image is a bit taller than the CardView and you set it to fitStart, there may be some extra space on the right.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/nature"
android:scaleType="cropCenter"
android:adjustViewBounds="true"
android:id="@+id/exercise_picture"/>
Upvotes: 1