saulmm / CoordinatorBehaviorExample

2.71k stars 589 forks source link

Fix toolbar at the top of the screen? #12

Closed igoriols closed 8 years ago

igoriols commented 9 years ago

Hey Saúl, this is a great example! What if I need to fix the toolbar at the top of the screen? Can you give me some tips to handle this?

Thanks in advance!

wingsum93 commented 8 years ago

you can simply search google "custome the actionbar android " , can found lost of example......... this post focus make the actionbar collapse and coordination layout

igoriols commented 8 years ago

Hahaha, thanks for the "tip" @wingsum93. But just to be clear, I already did the search. If you saw Saúl's example, you could see that the toolbar moves to the top while the dog picture moves together. So I asked how to obtain the same effect with the toolbar fixed at the top.

Saúl already gave me some good tips on how to do that.

Be careful with this kind of answer in StackOverflow, you can easily get a -1.

Peace!

saulmm commented 8 years ago

Yes, you could, currently, the layout_anchor with the layout_anchorGravity attributes in the toolbar on my example, makes the toolbar tiered to the top of the layout within a title and a subtitle.

<android.support.v7.widget.Toolbar
        android:id="@+id/main.toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?colorPrimary"
        app:layout_anchor="@id/main.linearlayout.title"
        app:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:title=""
        >

If you remove these anchor attributes, the toolbar will stay at the top of the screen. Since the dependency of the custom coordinator behavior that makes the round image translate to the left corner of the screen is the toolbar. You'll have to make the proper changes to handle that, setting another view as your dependency in the behavior. Here -> http://saulmm.github.io/mastering-coordinator there is an small explanation of how the coordinator behaviors work referring this example.

Thanks!

drinfernoo commented 6 years ago

I've been trying to figure this out as well, in order to have my Toolbar, containing the "Back" arrow, stay at the top of the screen, rather than starting the middle of the screen and scrolling up.