Как изменить расположение панели инструментов ниже ImageView в CollapsingToolbarLayout, в середине макета? - PullRequest
0 голосов
/ 28 апреля 2020

Я хочу построить макет, как показано ниже:

toolbar in the middle of layout

Макет по умолчанию выглядит примерно так:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:fitsSystemWindows="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:toolbarId="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|snap"
            app:contentScrim="?attr/colorPrimary">

             <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:srcCompat="@drawable/lionking" /> 

             <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:menu="@menu/my_menu"
                app:layout_collapseMode="pin"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:theme="?attr/actionBarTheme" /> 
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
        <include layout="@layout/item_nested_scrollview"/>
    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Теперь, чтобы изменить расположение панели инструментов ниже imageView, я создал новый файл с linearlayout (вертикальная ориентация) и поместил Imageview и панель инструментов внутри него, так что приведенный выше код выглядит так:

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:fitsSystemWindows="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:toolbarId="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|snap"
        app:contentScrim="?attr/colorPrimary">

        <include layout="@layout/toolbar_in_middle"/>

    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

    <include layout="@layout/item_nested_scrollview"/>

</androidx.core.widget.NestedScrollView>

Файл LinearLayout "toolbar_in_middle. xml", который включен в вышеуказанный файл:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|snap"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax"
        app:srcCompat="@drawable/lionking" />

    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:menu="@menu/my_menu"
        app:layout_collapseMode="pin" />
</LinearLayout>

панель инструментов отображения макета в середине макета, как и требовалось, но поведение не работает должным образом, ImageView не работает в режиме Parralax, а также панель инструментов не работает, как предполагается, чтобы действовать. хотя для обоих есть атрибуты app: layout_scrollFlags.

  • как отладить эту проблему или как устранить ее?
  • Другой вопрос касается прозрачности панели инструментов, как ее правильно сделать?

конечная цель - создать макет, его поведение похоже на макет в приложении погоды Samsung.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...