Остановить прокрутку CollapsingToolbarLayout, чтобы он не рухнул полностью

У меня есть настройка CollapsingToolbarLayout, и я помещаю туда обои. Я хочу быть в состоянии остановить его от разрушения полностью.

Я пробовал minheight и многие другие вещи, но не могу понять.

Как я могу заставить его перестать сворачиваться на второй скриншот?

Просмотр при загрузке активности

Загруженный просмотр

Желаемый пункт остановки

Желаемый пункт остановки

Текущая точка остановки

Текущая точка остановки


person BigDX    schedule 23.07.2015    source источник
comment
Просто красивый макет заслуживает плюса!   -  person Mahm00d    schedule 27.01.2016


Ответы (3)


CollapsingToolbarLayout очень тесно работает с Toolbar, и поэтому свернутая высота зависит от панели инструментов.

Мне удалось решить вашу проблему, используя этот макет (Обратите внимание, он входит в обычную настройку CoordinatorLayout/AppBarLayout, с помощью Fab и NestedScrollView или RecyclerView):

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    app:statusBarScrim="?attr/colorPrimaryDark"
    app:contentScrim="@android:color/transparent"
    app:titleEnabled="false"
    >
    <!-- There isnt a contentSCrim attribute so the toolbar is transparent after being
         collapsed
         Disabled the title also as you wont be needing it -->

    <ImageView
        android:id="@+id/image_v"
        android:layout_width="match_parent"
        android:layout_height="360dp"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        android:src="@drawable/md2"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="parallax"
        tools:ignore="ContentDescription"
        />
        <!-- Normal Imageview. Nothing interesting -->

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="168dp"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        />
        <!-- The toolbar is styled normally. However we disable the title also in code.
        Toolbar height is the main component that determines the collapsed height -->

    <TextView
        android:text="@string/app_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?attr/colorPrimaryDark"
        android:paddingLeft="72dp"
        android:paddingRight="0dp"
        android:paddingBottom="24dp"
        android:paddingTop="24dp"
        android:textColor="@android:color/white"
        android:textAppearance="@style/TextAppearance.AppCompat.Headline"
        />
        <!-- The title textView -->

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

Связанная деятельность выглядит следующим образом:

    ...
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Disable toolbar title
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    ...

Вот видео взаимодействия

введите описание изображения здесь

person efemoney    schedule 25.08.2015

Я столкнулся с той же проблемой.

Сначала я просто установил высоту панели инструментов, как описано в предыдущих ответах, и это работает.

Но это привело к другой проблеме. Представление панели инструментов потребляет события касания, поэтому мое сворачивающееся представление (то есть MapView) не принимает никаких событий касания в той части, которая перекрывается панелью инструментов.

Наконец, мое решение — удалить панель инструментов из CollapsingToolbarLayout. В моем случае это нормально, потому что я использовал его только для ограничения коллапса. И установить минимальную высоту сворачивания в onCreateView следующим образом:

CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120);
person CI Apps    schedule 10.01.2016
comment
Хорошая идея! Вы можете установить минимальную высоту в файле макета вместо кода. - person Mehrzad Chehraz; 11.01.2017
comment
Если у вас есть панель инструментов внутри CollapsingToolbarLayout, вы также можете добавить к ней отступ. :) - person Milack27; 28.01.2020

Просто добавьте желаемую высоту остановки на панель инструментов и установите app:contentScrim="#00000000" для CollapsingToolbarLayout.

  <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="#00000000"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <ImageView
            android:id="@+id/ImageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/image"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="100dp"
        /> <!-- set desired stop-height as height -->

    </android.support.design.widget.CollapsingToolbarLayout>
person Ciron    schedule 08.09.2015
comment
Проблема, с которой я столкнулся, заключается в том, что как только высота панели инструментов изменяется, выравнивание текста заголовка, предоставляемого панелью инструментов, полностью искажается. Мне пришлось добавить пользовательское представление, содержащее текстовое представление со всеми видами жестко запрограммированных полей, чтобы все было правильно. - person JHH; 19.04.2016