AppBarLayout and CollapsingToolbarLayout not able to contain Button?

試著忘記壹切 提交于 2019-11-29 23:27:42

问题


I am working with this following Repository here:

CheeseSquare Repo via Chris Banes

Overall it is good repository but lacks complex layout schemes. I want to achieve something like this:

Where the "DO SOMETHING" button is contained inside AppBarLayout and nested inside CollapsingToolbarLayout, and it collapses as you scroll up. That is my original thought, but it doesn't seem to give me the behavior I am looking for.

This is what my XML Layout looks like:

<android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.AppBarLayout>

    <android.support.design.widget.CollapsingToolbarLayout>

        <ImageView />

        <android.support.v7.widget.Toolbar />

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

    <Button/>

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

<android.support.v4.widget.NestedScrollView>

    <LinearLayout>

        <android.support.v7.widget.CardView>
            <LinearLayout>
                <TextView/>
            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

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

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

How would I go about accomplishing something like that?


回答1:


I was able to solve this issue by implementing the following:

<android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.AppBarLayout>

    <android.support.design.widget.CollapsingToolbarLayout
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar />

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

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

    <LinearLayout
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >

        <!-- BUTTON INSERTED HERE -->
        <Button />
        <android.support.design.widget.TabLayout />
        <android.support.v4.view.ViewPager />

    </LinearLayout>

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


来源:https://stackoverflow.com/questions/31216336/appbarlayout-and-collapsingtoolbarlayout-not-able-to-contain-button

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