2015-08-14 119 views
1

我一直在尋找這個瓦特/沒有運氣。 Android支持設計庫似乎只用於在圖像上進行視差設計,但我想要的頭像更像是一個幀佈局或線性佈局,其中包含一個包含覆蓋文本和漸變頂點的圖像的元素。也就是說,一個更復雜的頭文件會縮小文本的大小,以使視差進入狀態欄標題。Android協調佈局與視差標題線性佈局?

有誰知道如何做到這一點?我試着築巢一個NestedScrollLayout但是這不是我想要做的任何:-(

+0

你能給的另一應用這種效果的例子嗎?我真的不明白你在問什麼...... –

+0

我希望我有一個例子...我們的設計師決定讓它變得具有挑戰性:-( 想象一下Google Play商店的應用程序列表,圖片頂部。一個進度條,評級星,文本,漸變等(即它不只是一個圖像),保持其餘的行爲,向上滾動,圖像及其上的所有東西都會隱藏,所以只有工具欄可見。 – kenyee

+0

仍然不完全理解你在問什麼......在我的腦海中,我想象到當頁面滾動時,圖像本身會滾動,但評分星星,文本等會摺疊成工具欄。如果這兩個狀態都有一些圖像/線框,那麼這會非常有幫助...... –

回答

2

可以使用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>