繁体   English   中英

如何在CoordinatorLayout中向工具栏显示固定视图

[英]How to show pinned view to Toolbar in CoordinatorLayout

如何在具有Material Design实现的AppBarLayout或工具栏上显示视图细节,如下所示:

在此输入图像描述

您需要将CoordinatorLayout作为您的父ViewGroup并将您的详细信息视图锚定到工具栏,在我的情况下它是CollapsingToolbarLayout。

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/annonce.main.coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded"
    android:text="hello"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/flexible.example.appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hello"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/flexible.example.collapsing"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:expandedTitleMarginBottom="94dp"
            android:text="hello"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleTextAppearance="@android:style/TextAppearance.Inverse"
            app:contentScrim="?colorPrimary">

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:tint="#BB3E50B4"
                android:scaleType="centerCrop"
                />

            <android.support.v7.widget.Toolbar
                android:id="@+id/flexible.example.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@null"
                android:title="hello"
                app:layout_collapseMode="pin"
                />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="250dp"
        android:background="@android:color/holo_green_light"
        app:layout_anchor="@id/flexible.example.collapsing"
        app:layout_anchorGravity="bottom|center_horizontal"
        tools:ignore="RtlHardcoded"
        ></LinearLayout>
</android.support.design.widget.CoordinatorLayout>

这是我的布局预览:

http://oi64.tinypic.com/15dwfv4.jpg

最有趣的部分是LinearLayout

        app:layout_anchor="@id/flexible.example.collapsing"
        app:layout_anchorGravity="bottom|center_horizontal"

其中描述了应该固定详细信息布局的位置。

希望它会有所帮助

暂无
暂无

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

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