Fixed
Status Update
Comments
ma...@gmail.com <ma...@gmail.com> #2
ni...@gmail.com <ni...@gmail.com> #3
Yes, I should have mentioned it.
And I'm using com.android.tools.build:gradle:2.0.0-beta6
And I'm using com.android.tools.build:gradle:2.0.0-beta6
ch...@google.com <ch...@google.com>
zt...@google.com <zt...@google.com> #4
Hi,
Let me know if scaleType='fitXY' can be a workaround for you , in order to get the image look sharp.
The marshmallow Vs Lollipop is due to a special scaling treatment added into marshmallow.
Also, for your comments:
"
Correct behavior:
The vector drawable should scale without quality loss. So if we want to use the same asset in 3 different sizes in our application, we don't have to duplicate vector_drawable.xml 3 times with different hardcoded sizes.
"
Even though I totally agree this should be the case, in reality, the Android platform has performance concern such that we have not reach the ideal world yet.
So it is actually recommended to use 3 different vector_drawable.xml for better performance if you are sure you want to draw 3 different size on the screen at the same time.
The technical detail is basically we are using a bitmap under the hook to cache the complex path rendering, such that we can get the best redrawing performance, on a par with redrawing a bitmap drawable.
Let me know if scaleType='fitXY' can be a workaround for you , in order to get the image look sharp.
The marshmallow Vs Lollipop is due to a special scaling treatment added into marshmallow.
Also, for your comments:
"
Correct behavior:
The vector drawable should scale without quality loss. So if we want to use the same asset in 3 different sizes in our application, we don't have to duplicate vector_drawable.xml 3 times with different hardcoded sizes.
"
Even though I totally agree this should be the case, in reality, the Android platform has performance concern such that we have not reach the ideal world yet.
So it is actually recommended to use 3 different vector_drawable.xml for better performance if you are sure you want to draw 3 different size on the screen at the same time.
The technical detail is basically we are using a bitmap under the hook to cache the complex path rendering, such that we can get the best redrawing performance, on a par with redrawing a bitmap drawable.
ni...@gmail.com <ni...@gmail.com> #5
Yes, with scaleType='fitXY' the image looks great on Lollipop.
Thanks for the explanation, that makes sense.
I didn't read about this elsewhere, it might me a good idea to talk about it in the doc, to help other devs.
Thanks for the explanation, that makes sense.
I didn't read about this elsewhere, it might me a good idea to talk about it in the doc, to help other devs.
ka...@gmail.com <ka...@gmail.com> #6
Had the same problem, scaleType='fitXY' worked for me too. Thanks!
bo...@gmail.com <bo...@gmail.com> #7
Confirming both the bug and the scaleType solution.
vi...@gmail.com <vi...@gmail.com> #8
Having same problem on Android 5.0.1 and its working fine on Android 4.4.4 and Android 6.0.1. `scaleType='fitXY'` does solve the issue when the `ImageView` has specified and wrap_content as its height and width. But `scaleType='fitXY'` doesn't work when the `ImageView` has height and width as `match_parent`
cl...@gmail.com <cl...@gmail.com> #9
[Comment deleted]
go...@gmail.com <go...@gmail.com> #10
I used a vector drawable as a shared element. It loses scaling upon exit transition
zt...@google.com <zt...@google.com> #11
This should be fixed in the upcoming new support lib.
zt...@google.com <zt...@google.com> #12
This should be fixed in the upcoming new support lib.
al...@android.com <al...@android.com> #13
Sweeping old FutureRelease issues. This was released in 23.4.0 or earlier.
ki...@gmail.com <ki...@gmail.com> #14
This issue is still there.
[Deleted User] <[Deleted User]> #15
[Comment deleted]
ej...@gmail.com <ej...@gmail.com> #16
Agreed, the issue is still there.
gl...@gmail.com <gl...@gmail.com> #17
Issue is also persisting for me
ra...@gmail.com <ra...@gmail.com> #18
The issue still exists in support lib 25.3.1
zt...@google.com <zt...@google.com> #19
Hi, ragunathan / Ryan / Eric / Kislay,
Could you provide an example app, which demonstrate the problem you saw ?
Thanks!
Could you provide an example app, which demonstrate the problem you saw ?
Thanks!
hi...@gmail.com <hi...@gmail.com> #20
In my situation the aspect ratio of the vector image is not maintained when using an ImageButton with flexible size (using layout_weight), or with a fixed size but no the same value for weight and height.
<ImageButton
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:padding="5dp"
app:srcCompat="@drawable/ic_,,"
/>
but when using fixed size for width and height (both the same value) there is no problem:
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:srcCompat="@drawable/ic_..."
/>
Tested with Android SDK version 16. It works fine in both cases with Android 6.0
<ImageButton
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:padding="5dp"
app:srcCompat="@drawable/ic_,,"
/>
but when using fixed size for width and height (both the same value) there is no problem:
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:srcCompat="@drawable/ic_..."
/>
Tested with Android SDK version 16. It works fine in both cases with Android 6.0
zt...@google.com <zt...@google.com> #21
Only these scaleType (listed below) will keep the aspect ratio of the Drawable( either bitmap or VectorDrawable). And "fixXY" won't. Feel free to try a bitmap drawable, and see the same behavior.
"
ImageView.ScaleType CENTER
Center the image in the view, but perform no scaling.
ImageView.ScaleType CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
ImageView.ScaleType CENTER_INSIDE
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
"
"
ImageView.ScaleType CENTER
Center the image in the view, but perform no scaling.
ImageView.ScaleType CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
ImageView.ScaleType CENTER_INSIDE
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
"
dj...@gmail.com <dj...@gmail.com> #22
I solve my problem just change size of vector image. From the first it was resource with:
<vector xmlns:android="http://schemas.android.com/apk/res/android "
xmlns:aapt="http://schemas.android.com/aapt "
android:width="24dp"
android:height="24dp"
android:viewportHeight="300"
android:viewportWidth="300">
And I've changed it to 150dp (size in ImageView in layout with this vector resource):
<vector xmlns:android="http://schemas.android.com/apk/res/android "
xmlns:aapt="http://schemas.android.com/aapt "
android:width="150dp"
android:height="150dp"
android:viewportHeight="300"
android:viewportWidth="300">
It's working for me.
<vector xmlns:android="
xmlns:aapt="
android:width="24dp"
android:height="24dp"
android:viewportHeight="300"
android:viewportWidth="300">
And I've changed it to 150dp (size in ImageView in layout with this vector resource):
<vector xmlns:android="
xmlns:aapt="
android:width="150dp"
android:height="150dp"
android:viewportHeight="300"
android:viewportWidth="300">
It's working for me.
ma...@gmail.com <ma...@gmail.com> #23
This issue still exists.
I run my app on a Android 5.1 device.
It works fine with fitXY, but loss quality with fitCenter
layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android "
xmlns:app="http://schemas.android.com/apk/res-auto "
xmlns:tools="http://schemas.android.com/tools "
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingActivity">
<ImageButton
android:id="@+id/imageButtonBrightness"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_settings_brightness"
app:layout_constraintBottom_toTopOf="@id/imageButtonWifi"
app:layout_constraintEnd_toStartOf="@id/imageButtonVolume"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButtonVolume"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_volume_up"
app:layout_constraintBottom_toTopOf="@id/imageButtonBattery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageButtonBrightness"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButtonWifi"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_wifi"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/imageButtonBattery"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageButtonBrightness" />
<ImageButton
android:id="@+id/imageButtonBattery"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_battery_std"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageButtonWifi"
app:layout_constraintTop_toBottomOf="@id/imageButtonVolume" />
</androidx.constraintlayout.widget.ConstraintLayout>
I run my app on a Android 5.1 device.
It works fine with fitXY, but loss quality with fitCenter
layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="
xmlns:app="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingActivity">
<ImageButton
android:id="@+id/imageButtonBrightness"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_settings_brightness"
app:layout_constraintBottom_toTopOf="@id/imageButtonWifi"
app:layout_constraintEnd_toStartOf="@id/imageButtonVolume"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButtonVolume"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_volume_up"
app:layout_constraintBottom_toTopOf="@id/imageButtonBattery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageButtonBrightness"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButtonWifi"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_wifi"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/imageButtonBattery"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageButtonBrightness" />
<ImageButton
android:id="@+id/imageButtonBattery"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_battery_std"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/imageButtonWifi"
app:layout_constraintTop_toBottomOf="@id/imageButtonVolume" />
</androidx.constraintlayout.widget.ConstraintLayout>
Description
Version used: 23.2.0
Theme used: Theme.AppCompat.Light.DarkActionBar
Devices/Android versions reproduced on: Nexus 4 on 5.1.1, Emulator on 4.4
Works great on Android 6
- Relevant code to trigger the issue:
- New android studio project (Blank Activity Template), with com.android.support:appcompat-v7:23.2.0. Just have to update activity_main.xml and add vector_drawable.xml
- activity_main.xml layout:
<LinearLayout
xmlns:android="
xmlns:app="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#1976D2"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="fr.zemap.issueandroidvector.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal size:"/>
<ImageView
android:id="@+id/normalImageIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/vector_drawable"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bigger size:"/>
<ImageView
android:id="@+id/bigImageIV"
android:layout_width="384dp"
android:layout_height="384dp"
app:srcCompat="@drawable/vector_drawable"/>
</LinearLayout>
- vector_drawable.xml taken from here
<vector
xmlns:android="
android:width="64dp"
android:height="64dp"
android:viewportHeight="32"
android:viewportWidth="32">
<path
android:fillColor="#8fff"
android:pathData="M20.5,9.5
c-1.955,0,-3.83,1.268,-4.5,3
c-0.67,-1.732,-2.547,-3,-4.5,-3
C8.957,9.5,7,11.432,7,14
c0,3.53,3.793,6.257,9,11.5
c5.207,-5.242,9,-7.97,9,-11.5
C25,11.432,23.043,9.5,20.5,9.5z"/>
</vector>
What happened:
On Marshmallow everything works great.
On Lollipop and KitKat (Nexus 4, Android 5.1.1), when the ImageView has the same size of the drawable, there is no problem. But when the ImageView is bigger, the vector doesn't scale well, and the image ends up beeing blurry, as if it was a png.
Correct behavior:
The vector drawable should scale without quality loss. So if we want to use the same asset in 3 different sizes in our application, we don't have to duplicate vector_drawable.xml 3 times with different hardcoded sizes.