How to make a collapsing toolbar in android?

孤人 提交于 2019-12-12 13:26:01

问题


so im trying to implement a simple collapsing toolbar, but I don't think my xml layout is correct. The text is appearing the image and when I scroll down, I can't scroll back up to see the image. Hope you guys can help!

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/cardInfo_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/cardInfo_collapsing"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/image_kyoto"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello there"
                android:textSize="30dp"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello there"
                android:textSize="30dp"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello there"
                android:textSize="30dp"/>        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hello there"
            android:textSize="30dp"/>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Here's the image


回答1:


Your ImageView should have attribute called

app:layout_collapseMode="parallax"

If you want to add Toolbar to your Layout there should be attribute called

app:layout_collapseMode="pin"

And finally You missed one attribute for NestedScrollView.

app:layout_behavior="@string/appbar_scrolling_view_behavior"



回答2:


in your ImageView, add the following attribute:

app:layout_collapseMode="parallax"

Also, in your NestedScrollView tag, add the following:

app:layout_behavior="@string/appbar_scrolling_view_behavior"


来源:https://stackoverflow.com/questions/39881879/how-to-make-a-collapsing-toolbar-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!