0

Тут мне написали как сделать прокрутку в Toolbar, но при изменении разметки activity на

<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:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        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:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@raw/nocover"
            app:layout_collapseMode="parallax" />

        <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" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

В toolbar пропадает и прокрутка и подзаголовок, почему?

1 ответ 1

1

Прокрутка пропадает потому что теперь за Title ответственен CollapsingToolbarLayout. Тем же способом прокрутку ему поставить не удастся, так как он не содержит полей TextView, которые можно изменить рефлексией. Первое что приходит в голову - поставить ему пустой тайтл

CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle("");

добавить в разметку внутрь тулбара и внутрь CollapsingToolbarLayout два TextView, что то вроде:

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

        <TextView
            android:id="@+id/expanded_TV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TITLE TITLE"
            android:textSize="30sp"
            android:layout_gravity="center"
            android:textAlignment="center"/>

        <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/AppTheme.PopupOverlay">

            <TextView
                android:id="@+id/collapsed_TV"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TITLE TITLE "
                />
        </android.support.v7.widget.Toolbar>

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

предложенным вам методом сделать их прокручиваемыми и дописать CoordinatorLayout.Behavior для expanded_TV, в котором анимировать ее в зависимости от координаты нижней границы CollapsingToolbarLayout, таким же образом анимировать collapsed_TV.

1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.