Подтвердить что ты не робот

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

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

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

Как я могу заставить его прекратить свертывание ко второму снимку экрана?

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

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

Желаемая точка остановки

Желаемая точка остановки

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

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

4b9b3361

Ответ 1

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

Я смог решить вашу проблему с помощью этого макета ( Примечание, он переходит в обычную установку CoordinatorLayout/AppBarLayout, с Fab и a 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);
    ...

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

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

Ответ 2

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

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

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

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

CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120);

Ответ 3

Просто добавьте нужную стоп-высоту на панель инструментов и установите 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>