简体   繁体   English

工具栏下的 AppBarLayout

[英]AppBarLayout under a toolbar

I have a CollapsingToolbarLayout which contains a viewPager which allows images to be scrolled horizontally.我有一个 CollapsingToolbarLayout,它包含一个允许图像水平滚动的 viewPager。 this viewPager is located under a toolBar.此 viewPager 位于工具栏下方。 The problem is that my images are cut off at the top, hidden by the toolbar.问题是我的图像在顶部被切断,被工具栏隐藏。 Is it possible to position the AppBarLayout and / or the CollapsingToolbarLayout under the toolBar to obtain the complete visualization of my images.是否可以在工具栏下放置 AppBarLayout 和/或 CollapsingToolbarLayout 以获得我的图像的完整可视化。 i did some testing but i can't get the result i want.我做了一些测试,但我无法得到我想要的结果。 any advice would be welcome.任何的建议都受欢迎。 thank you in advance先感谢您

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">


<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="208dp"
    android:theme="@style/AppTheme.AppBarOverlay">

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


    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/introSliderViewPager"
        android:layout_width="match_parent"
        android:layout_height="219dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fl_wrapper" />


    <FrameLayout
    android:id="@+id/fl_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:ignore="MissingConstraints">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbarDecouverte"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorNavBarre"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme" />

   </FrameLayout>

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

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

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/indicatorContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintTop_toBottomOf="@+id/introSliderViewPager" />

    <com.google.android.material.tabs.TabLayout
    android:id="@+id/tabLayoutDecouverte"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="2dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/indicatorContainer"
    app:tabIndicatorAnimationDuration="150"
    app:tabIndicatorColor="#FB0303"
    app:tabIndicatorFullWidth="false">

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/description" />

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/pratique" />

    </com.google.android.material.tabs.TabLayout>

    <androidx.viewpager.widget.ViewPager
    android:id="@+id/viewPagerDecouverte"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="5dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tabLayoutDecouverte" />

    </LinearLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

myActivity我的活动

current result当前结果

I do not know if this is the right method, below the result after a few tests, for me it works.我不知道这是否是正确的方法,经过几次测试后的结果对我来说是有效的。 you never know it can help.你永远不知道它会有所帮助。

    <?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"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"
     tools:context=".MainActivity">


    <com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:theme="@style/AppTheme.AppBarOverlay">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_below="@+id/toolbar"
            android:fitsSystemWindows="true"
            android:gravity="bottom"
            android:scaleType="centerCrop">


            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/introSliderViewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent">


            </androidx.viewpager2.widget.ViewPager2>

        </RelativeLayout>


        <FrameLayout
            android:id="@+id/fl_wrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="MissingConstraints">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbarDecouverte"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorNavBarre"
                android:minHeight="?attr/actionBarSize"
                android:theme="?attr/actionBarTheme" />

        </FrameLayout>

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

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

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
        android:id="@+id/indicatorContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintTop_toBottomOf="@+id/introSliderViewPager" />

        <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayoutDecouverte"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/indicatorContainer"
        app:tabIndicatorAnimationDuration="150"
        app:tabIndicatorColor="#FB0303"
        app:tabIndicatorFullWidth="false">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/description" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/pratique" />

        </com.google.android.material.tabs.TabLayout>

        <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPagerDecouverte"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="5dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tabLayoutDecouverte" />

        </LinearLayout>

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM