2016-03-14 14 views
0

我的CoordinatorLayout出現問題。當我向上滾動時,我希望imageview完全消失。協調員行爲ImageView

這是觀點的例子後,我向上滾動 http://imgur.com/KI8kouG

planet_main.xml

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

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/ctlLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     app:titleEnabled="false" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="64dp" 
      android:layout_marginRight="64dp" 
      android:layout_marginTop="32dp" 
      android:fitsSystemWindows="true" 
      android:orientation="vertical" 
      app:layout_collapseMode="parallax" 
      > 

      <ImageView 
       android:id="@+id/userAvatar" 
       android:layout_width="@dimen/fab_large" 
       android:layout_height="@dimen/fab_large" 
       android:layout_gravity="center_horizontal" 
       android:src="@drawable/pl_alderaan" 
       android:padding="2dp" 
       /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       > 

       <TextView 
        android:id="@+id/userLogin" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="4dp" 
        android:gravity="center_horizontal" 
        android:maxLines="1" 
        android:textSize="36sp" 
        android:text="Header" 
        android:textColor="@color/white"/> 

       <TextView 
        android:id="@+id/userName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="4dp" 
        android:gravity="center_horizontal" 
        android:maxLines="1" 
        android:textSize="16sp" 
        android:textStyle="bold" 
        android:text="Subheader" 
        android:textColor="@color/white" 
        /> 
      </LinearLayout> 
     </LinearLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 
    </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:background="@drawable/card" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:layout_gravity="fill_vertical"> 

    <TextView 
     android:id="@+id/txtDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:textColor="@color/text" 
     android:gravity="center" 
     android:text="@string/lorum" 
     android:textSize="14sp" 
     android:layout_margin="10dp" /> 


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

我也試圖實現找到幾個例子之後的自定義行爲特別是這個GitHub應用示例Gitskarios,因爲我們的佈局很相似,但它不能解決我的問題。我還讀了Here,由於它不是一個直接的孩子,所以它可能沒有被打電話。如何保持我的佈局並淡入/隱藏imageview?

回答

0

簡單的方法是在CollapsingToolbarLayout上使用app:contentScrim="@color/your_toolbar_color"。從技術上講,這不會擺脫圖像,它只會用你的工具欄的顏色再次覆蓋它,但它會似乎淡出和英寸

+0

這解決了我的問題!非常感謝你,這簡直令人尷尬。 – strykstaguy