How can I use CollapsingToolbarLayout over scrollview?
I want to create this parallax view for the top banner.
I tried this but it doesn't work:
<?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>
All views above the nav bar are inflated with a fragment. I want the whole parallax thing to be on the home tab only.
+3
source to share
2 answers
Try it. Declare this collapsingToolbarLayout instance as global in your java class.
private CollapsingToolbarLayout collapsingToolbarLayout;
In the onCreate () operation, the method is placed below the code
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setExpandedTitleColor(Color.TRANSPARENT); collapsingToolbarLayout.setCollapsedTitleTextColor(ContextCompat.getColor(this, R.color.color_white));
0
source to share