Proloy
Proloy

Reputation: 363

Floating ImageView on ActionBar in Android?

I am fairly new to android development and trying to learn as much as i can by doing problems, recently i have come up with a problem related to xml designing where there is a

floating Imageview on top of the Actionbar

. I am calling it floating because it is not in the action bar, it is just positioned center and overlapping the action bar. The Image would describe it properly - enter image description here

The Action bar is not collapsing and the round image is not a button just a simple imageview. Now how can i achieve this design?? any kind of help would be appreciated.

Upvotes: 0

Views: 431

Answers (1)

Faiz Malkani
Faiz Malkani

Reputation: 313

Using a CoordinatorLayout allows you to use an anchor property on views which will make implementing this really simple.

According to the documentation:

Children of a CoordinatorLayout may have an anchor. This view id must correspond to an arbitrary descendant of the CoordinatorLayout, but it may not be the anchored child itself or a descendant of the anchored child. This can be used to place floating views relative to other arbitrary content panes.

Which means, all you'll need to do is use a CoordinatorLayout as the top-level container, wrap the toolbar in an AppBarLayout, and anchor the image view to that.

Upvotes: 1

Related Questions