I've a collapsingToolbar with a ImageView inside, the problem it's when the device it's in portrait/landscape the image loads correctly, next when the device it's rotated again to portrait the image it's cropped. I've tried without cache but the result it's the same.
My xml:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/AppTheme.CollapsingToolbar.Text.Transparent"
app:contentScrim="?attr/colorPrimaryDark"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/AppTheme.CollapsingToolbar.Text.Transparent"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed|enterAlways"
app:title="">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView_backdrop"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<include
layout="@layout/scrim_layout"/>
<TextView
android:id="@+id/textView_expanded_title"
style="@style/AppTheme.CollapsingToolbar.TextView.Multiline"/>
<include layout="@layout/progress_bar_color_accent"/>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@color/colorAccent"/>
</android.support.design.widget.CollapsingToolbarLayout>
My glide loading in the fragment:
Glide.with(getActivity()).load(mOptimalUrl).centerCrop().into(mImageViewBackdrop);
I've done some research and it seems it's something related with Glide measuring the view or the collapsingToolbar/CoordinatorLayout giving the wrong imageView size to Glide. I'am saying this because i attached a click listener to the imageView and forced glide to reload again and when it's reloaded Glide do it correctly.
UPDATE:
I'am measuring the view and displaying in log to see:
When it starts in portrait:
WIDTH -> 1080 HEIGHT -> 768 (correct size)
Rotate to landscape:
WIDTH -> 1080 HEIGHT -> 768 (wrong size, this size it's from the previous one)
Rotate again to portrait:
WIDTH -> 1794 HEIGHT -> 768 (wrong size, this size it's from the previous one the landscape mode)
I'am starting to think the problem it's not from Glide, but from support library.
I have the same problem , if it is put back landscape the image is displayed well
I tried to repro (see above commit), but couldn't get it to misbehave, logging shows these measurements:
05-25 09:46:57.966 22224-22224/com.bumptech.glide.supportapp.v3 V/GLIDE: .onResourceReady(GlideBitmapDrawable@374eaca(1080x768@RGB_565), http://www.visitcentrodeportugal.com.pt/wp-content/uploads/2013/01/museu-francisco-tavares-por.jpg, Target for: v7.widget.AppCompatImageView{a8db43b V.ED..C.. ........ 0,0-1080,768 #1020006 android:id/icon}(params=-1x768->size=1080x768), async, first)
rotate to landscape
05-25 09:47:02.134 22224-22224/com.bumptech.glide.supportapp.v3 V/GLIDE: .onResourceReady(GlideBitmapDrawable@1a0f55d(1794x768@RGB_565), http://www.visitcentrodeportugal.com.pt/wp-content/uploads/2013/01/museu-francisco-tavares-por.jpg, Target for: v7.widget.AppCompatImageView{f38fed2 V.ED..C.. ........ 0,0-1794,768 #1020006 android:id/icon}(params=-1x768->size=1794x768), async, first)
rotate back to portrait
05-25 09:47:04.941 22224-22224/com.bumptech.glide.supportapp.v3 V/GLIDE: .onResourceReady(GlideBitmapDrawable@de73fd0(1080x768@RGB_565), http://www.visitcentrodeportugal.com.pt/wp-content/uploads/2013/01/museu-francisco-tavares-por.jpg, Target for: v7.widget.AppCompatImageView{bc7bbc9 V.ED..C.. ......ID 0,0-1080,768 #1020006 android:id/icon}(params=-1x768->size=1080x768), sync, first)
My Glide load line is in onCreate, where's yours? Can you try to create a small repro? As a quick and dirty workaround you may try mImageViewBackdrop.layout(0,0,0,0) just before Glide...., that sometimes helped in lists.
I solved use this https://github.com/bumptech/glide/issues/613#issuecomment-138920515
imageview.xml
<ImageView
android:id="@+id/cover_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/desc_empty"
android:fitsSystemWindows="true"
android:scaleType="centerCrop" />
Glide.with(this)
.load(entry.getCover_photo())
.asBitmap()
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new BitmapImageViewTarget(ivCover) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
super.onResourceReady(resource, glideAnimation);
Glide.with(ivCover.getContext())
.load(entry.getCover_photo())
.centerCrop().into(ivCover);
}
});
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Most helpful comment
I've done some research and it seems it's something related with Glide measuring the view or the collapsingToolbar/CoordinatorLayout giving the wrong imageView size to Glide. I'am saying this because i attached a click listener to the imageView and forced glide to reload again and when it's reloaded Glide do it correctly.
UPDATE:
I'am measuring the view and displaying in log to see:
When it starts in portrait:
WIDTH -> 1080 HEIGHT -> 768 (correct size)
Rotate to landscape:
WIDTH -> 1080 HEIGHT -> 768 (wrong size, this size it's from the previous one)
Rotate again to portrait:
WIDTH -> 1794 HEIGHT -> 768 (wrong size, this size it's from the previous one the landscape mode)
I'am starting to think the problem it's not from Glide, but from support library.