简体   繁体   English

android coordinatorlayout与视差标题中的linearlayout?

[英]android coordinatorlayout with a linearlayout in parallax header?

I've been looking everywhere for this w/ no luck. 我一直在到处寻找这种运气。 The Android Support Design library seems to be designed for doing parallax only on an image, but I want a header that's more like a framelayout or linearlayout with a bunch of elements including an image w/ overlaid text and gradients on top of it. Android支持设计库似乎设计为仅对图像进行视差处理,但是我想要的标头更像是framelayout或linearlayout,其中包含一堆元素,其中包括图像w /覆盖文本和渐变。 Ie, a more complicated header that shrinks w/ text that parallaxes into the status bar title w/ a different font size. 即,更复杂的标头将带有视差的文本缩小为带有不同字体大小的状态栏标题。

Does anyone know how to do this? 有谁知道如何做到这一点? I tried nesting a NestedScrollLayout but that's not what I want to do either :-( 我尝试嵌套NestedScrollLayout,但这不是我想要做的:-(

You can use the CollapsingToolbarLayout 您可以使用CollapsingToolbarLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="10dp"
        android:background="@color/nav_view_header"
        app:expandedTitleMarginEnd="64dp">

        <RelativeLayout
            android:id="@+id/header_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_vp_placeholder_largo"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" >

            <!-- Your progress bar, rating stars, text, a gradient, etc. -->


        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nestedScroll"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <!-- Your scrolling content -->

</android.support.v4.widget.NestedScrollView>

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

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

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