0

После this урока, у меня есть CollapsingToolbarLayout:Использование CollapsingToolbarLayout, как я могу установить его как панель действий поддержки?

<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|enterAlways|enterAlwaysCollapsed"> 

     <ImageView 
      android:id="@+id/blurred_background" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:ignore="ContentDescription" /> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/defaultimage" 
      app:layout_collapseMode="parallax" 
      app:layout_collapseParallaxMultiplier="0.7" 
      tools:ignore="ContentDescription" 
      android:id="@+id/profilePicture" /> 


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

Однако, мне нужно использовать setSupportActionBar(), так что я могу использовать setTitle(), setHomeAsUpEnabled() и т.д. методы. Однако, видимо, CollapsingToolbarLayout не может быть отлит до Toolbar, а метод setSupportActionBar() принимает только метод Toolbar.

Есть ли способ замены для его установки?

+0

Пройдите https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout – Pavya

+0

Почему бы просто не обернуть ваш 'ImageView' в 'Панель инструментов'? –

+0

@MikeM. Хорошая идея, но похоже, что мои ImageView 's потеряли выравнивания, которые они имели. (Один из них был сосредоточен, теперь он находится слева от экрана. –

ответ

0

Попробуйте сделать что-то вроде этого:

<android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginBottom="70dp" 
     app:expandedTitleMarginEnd="10dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_collapseParallaxMultiplier="0.5" 
     app:layout_scrollFlags="scroll|enterAlways|snap"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="160dp" 
      android:gravity="bottom" 
      android:orientation="vertical" 
      app:layout_collapseMode="parallax"> 

      <ImageView 
       android:id="@+id/blurred_background" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       tools:ignore="ContentDescription" /> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:src="@drawable/defaultimage" 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0.7" 
       tools:ignore="ContentDescription" 
       android:id="@+id/profilePicture" /> 
     </LinearLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      app:contentInsetStartWithNavigation="0dp" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" /> 
    </android.support.design.widget.CollapsingToolbarLayout> 

Добавить свои взгляды изображения внутри LinearLayout/RelativeLayout и добавить панель инструментов в CollapsingToolbarLayout для достижения Toolbar функциональности.