Top of image set in ImageView is choppy during AppBarLayout

Asked 2 years ago, Updated 2 years ago, 80 views

http://i.imgur.com/ah4l5oj.gif
I would like to use AppBarLayout with the image like the one above

<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"
    tools:context="jp.co.nosan.myapplication6.AppBarLayoutActivity">

    <android.support.design.widget.AppBarLayout
        android: id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:expanded="false">

        <android.support.design.widget.CollappingToolbarLayout
            android: id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll | exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android: src="@drawable/slam_small"
                app:layout_collapseMode="parallax"
                tools:ignore="ContentDescription"/>
            <android.support.v7.widget.Toolbar
                android: id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAllways"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>


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

    <android.support.v4.widget.NestedScrollView
        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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_scrolling">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android: text="@string/large_text"/>

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android: id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"/>

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

But in this state, the top of the image seems to be cut off.
How can I display images without interruption?
If possible, please keep the ratio as it is

android

2022-09-30 21:16

1 Answers

The reason why it is disconnected at this time is that the android:scaleType in ImageView is centerCrop.

CenterCrop maintains the aspect ratio of the image, magnifies it to the width, and cuts out the protruding parts to display it.

I think there are many ways to keep the connection going, depending on the screen size, image size, margin, etc.


2022-09-30 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.