Fresco: Setting placeholder programmatically in hierarchy does not respect scaleType

Created on 19 Feb 2016  路  10Comments  路  Source: facebook/fresco

I'm using SimpleDraweeView as Toolbar background, for this i have set a fixed height in AppBarLayout and match_parent height for SimpleDraweeView, the image set programmatically for placeholder is getting stretched in height, even if i set programmatically the scale type to centerCrop.
This is my layout res:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="270dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/drawee_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:placeholderImageScaleType="centerCrop"
                app:layout_collapseMode="parallax" />
            <include layout="@layout/toolbar"/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content" />
</android.support.design.widget.CoordinatorLayout>

Most helpful comment

This is indeed a bug. Setting a placeholder image programmatically, ignores the "placeholderScaleType" set in xml.
I wanted to use fitCenter, and I had to go with this method:
target.getHierarchy().setPlaceholderImage(context.getResources().getDrawable(ressourceId), ScalingUtils.ScaleType.FIT_CENTER)

All 10 comments

I'm setting the placeholder with this call:
draweeImage.getHierarchy().setPlaceholderImage(R.drawable.background_test);

The drawable res named background_test:
background_test
The result i got:
result

You need to use app:placeholderImageScaleType="centerCrop" instead of app:actualImageScaleType="centerCrop"

@IanChilds even with app:placeholderImageScaleType i get the same result

try setting the scale type programmatically too at the same time that you set the image?

I'm calling this after setting the placeholder:
draweeImage.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
And i got the same result

You're calling the wrong method - should be placeholder, not actual image

I tried to find a placeholder method in hierarchy, but theres no placeholder method, so i figured out that setPlaceholderImage have an option to pass scaletype with the drawable, now it's working. Ty

This is indeed a bug. Setting a placeholder image programmatically, ignores the "placeholderScaleType" set in xml.
I wanted to use fitCenter, and I had to go with this method:
target.getHierarchy().setPlaceholderImage(context.getResources().getDrawable(ressourceId), ScalingUtils.ScaleType.FIT_CENTER)

Above answer is working for me

However, what is about this bug?
I think if we don't specify placeholderScaleType explicitly, Drawee should scaleType defined in xml, shouldn't it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sungerk picture sungerk  路  3Comments

cococool picture cococool  路  4Comments

qiiyue picture qiiyue  路  4Comments

amodkanthe picture amodkanthe  路  3Comments

satyarths picture satyarths  路  3Comments