[英]How to show pinned view to Toolbar in CoordinatorLayout
you need touse CoordinatorLayout as your parent ViewGroup and anchor your detail view to your toolbar, in my case it's CollapsingToolbarLayout. 您需要将CoordinatorLayout作为您的父ViewGroup并将您的详细信息视图锚定到工具栏,在我的情况下它是CollapsingToolbarLayout。
Here's my xml file: 这是我的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>
and here's a preview of my layout: 这是我的布局预览:
http://oi64.tinypic.com/15dwfv4.jpg http://oi64.tinypic.com/15dwfv4.jpg
The most interesting part is in LinearLayout
: 最有趣的部分是LinearLayout
:
app:layout_anchor="@id/flexible.example.collapsing"
app:layout_anchorGravity="bottom|center_horizontal"
which describes where your details layout should be pinned. 其中描述了应该固定详细信息布局的位置。
Hope it will help 希望它会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.