I trying to make image inside CollapsingToolbarLayout
scrollable (just like in Google Play app). Then I put NestedScrollView
inside CollapsingToolbarLayout
. ImageView resizes itself (see picture) forcibly (image is distorted).
How to make this thing work properly?
My layout
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="@color/pure_black75"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:background="@color/transparent"
android:maxHeight="200dp"
android:height="200dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/cat_stub"
app:layout_collapseMode="parallax" />
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:queryBackground="@android:color/transparent"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:background="@color/transparent"
android:maxHeight="200dp"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="230dp"
android:scaleType="fitXY"
android:src="@drawable/cat_stub"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="230dp"
android:scaleType="fitXY"
android:src="@drawable/cat_stub"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="230dp"
android:scaleType="fitXY"
android:src="@drawable/cat_stub"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<SeekBar
android:layout_marginLeft="-18dp"
android:layout_marginRight="-18dp"
android:id="@+id/audio_seekbar"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom"
android:thumb="@null"
android:layout_width="match_parent"
android:indeterminateDrawable="@drawable/apptheme_scrubber_progress_horizontal_holo_light"
android:progressDrawable="@drawable/apptheme_scrubber_progress_horizontal_holo_light"
android:layout_above="@id/video_play_pause"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:id="@+id/fab_play_pause"
android:height="20dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:minHeight="0dp"
android:scaleType="fitXY"
android:src="@drawable/fab_play_pause_selector"
app:layout_collapseMode="pin"
android:layout_marginTop="4dp"
android:padding="5dp"
app:backgroundTint="@color/white"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
android:layout_height="wrap_content"/>
You can try to change scaleType centerCrop: