13

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

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

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

Вид, когда активность загружается

Loaded View

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

Desired Stopping point

Текущий остановочный пункт

Current Stopping Point

+7

Просто красивая планировка заслуживает upvote! – Mahm00d

ответ

8

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); 
    ... 

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

enter image description here

1

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

Проблема, с которой я столкнулся, заключается в том, что, как только изменяется высота панели инструментов, выравнивание текста заголовка, предоставляемого панелью инструментов, полностью перепутано. Мне нужно было добавить пользовательский вид, содержащий текстовое представление со всеми видами жестко закодированных полей, чтобы все было правильно. – JHH

6

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

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

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

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

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

Хорошая идея!Вы можете установить минимальную высоту в файле макета вместо кода. –