Demonic218
Demonic218

Reputation: 923

How to stop an image from squishing into an imageview in android

Firstly I'm not sure if I've phrased the question correctly, but with some explaining hopefully i'd be able to get you to see what i'm trying to ask.

I've got an image view that sits at about 15% on the top half of the screen, lets say for example the height of the image view is 30px, however the image I put in that imageview has a height of 100px. Currently all 100px of the image is squishing into the 30px.

My question is how do I only show the 30px of the image instead of the full 100px which is squished into the 30px.

Here is my imageview

<ImageView
            android:id="@+id/top_overlay"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/background_section"
            app:layout_constraintBottom_toTopOf="@+id/top_guideline"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

Upvotes: 0

Views: 154

Answers (1)

Locdoc01
Locdoc01

Reputation: 733

Set the scaleType to center. Also set background to srcCompat. Following should work in ConstraintLayout:

<ImageView
    android:id="@+id/top_overlay"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:srcCompat="@drawable/background_section"
    android:scaleType="center"
    app:layout_constraintBottom_toTopOf="@+id/top_guideline"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Upvotes: 1

Related Questions