Reputation: 153
i'm trying to scale an imageview using following code which works fine
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="6000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2"
>
</scale>
</set>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
tools:src="@drawable/image"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintTop_toTopOf="parent"/>
But it also scales the height and width of the imageview as well. Is there a way to scale an image of imageview without making the view bigger?
Upvotes: 0
Views: 120
Reputation: 4236
This will not work because the ImageView
itself is scaled. So, no matter what the scaleType
or adjustViewBounds
is, the ImageView
still gets scaled. The image can't be scaled separately from the view, instead you can animate the padding of the ImageView
My suggestion would be to add the ImageView
in another view, for example a RelativeLayout
, set the RelativeLayout
to the size you want and then scale the ImageView
.
Doing this, the RelativeLayout
will remain the same size and can be used to do what your where intended to do, while the ImageView
is scaled.
Upvotes: 1
Reputation: 2434
You can make your image auto resize to fit the imageView like this
<ImageView
android:id="@id/img_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
adjustViewBounds
is the key to re-scale your image to fill the imageView
Upvotes: 0