问题
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