3

我想用頂部橫幅的視差效果來創建此視圖。如何在滾動視圖上方使用CollapsingToolbarLayout?

enter image description here

我試過,但它不工作:

<?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:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:layout_height="200dp" 
    android:layout_width="match_parent"> 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.AppCompatImageView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:background="@drawable/main_banner"/> 

    </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="@color/vahab_background"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@color/vahab_background"> 

     ... 

    </LinearLayout> 

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

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

所有導航欄上面的意見片段被誇大。 我只想要在主頁選項卡中的整個視差。在CoordinateLayout http://saulmm.github.io/mastering-coordinator

+0

請發表您的Java代碼也處理CollapsingToolbarLayout。 –

+0

@VinodPattanshetti你會建議一個代碼來正確處理它嗎? 我沒有在java中做任何事情。只是誇大了佈局。 – Mohsen

回答

1

尼斯博客嘗試了這一點。 在java類中聲明這個collapsingToolbarLayout實例爲全局的。

private CollapsingToolbarLayout collapsingToolbarLayout; 

在活動onCreate()方法把下面的代碼

collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
    collapsingToolbarLayout.setExpandedTitleColor(Color.TRANSPARENT); 
    collapsingToolbarLayout.setCollapsedTitleTextColor(ContextCompat.getColor(this, R.color.color_white)); 
+0

在那裏...做到了...我想用我的代碼知道這個問題! – Mohsen

+0

我沒有發現我做錯了什麼......但你解決方案的工作,現在已經足夠了...... – Mohsen

0

+0

試試我的上面的代碼,讓我知道如果你面臨任何問題。 –

+0

不,它沒有工作 – Mohsen

+0

你面臨的問題是什麼? –

相關問題