Currently working on a app where I need to add "share" and "add" buttons in the bottom right corner of a Collapsing toolbar
(for parallax effect).
Which might hide on scrolling or might sit on Actionbar
. Added the image of what i want to achieve. Currently have no clue on how to do this(tried with floating action buttons with anchors, but failed).
This is what is should look like:
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/htab_maincontent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:id="@+id/htab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/htab_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="13dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/htab_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:tabIndicatorHeight="@dimen/tabIndicatorHeight"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/htab_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
If you are using that in CollapsingToolbarLayout
, you can do this:
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarCollapse"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="@android:color/darker_gray"
android:minHeight="190dp"
android:src="@drawable/ic_email"
app:layout_collapseMode="parallax"
android:id="@+id/imageView8" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabmain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_add"
app:backgroundTint="@color/ColorAccent"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|end"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_alignTop="@+id/fabmain2"
android:layout_toStartOf="@+id/fabmain2"
android:layout_marginEnd="20dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabmain2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_add"
app:backgroundTint="@color/ColorAccent"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|end"
android:layout_marginRight="16dp"
android:layout_marginEnd="23dp"
android:layout_alignBottom="@+id/imageView8"
android:layout_alignParentEnd="true"
android:layout_marginBottom="29dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
Also, According to Google Material Design, i don't think if this is the standard way/or good way for two buttons!
Also, this is my idea (standard way):
You could add a Share action
with that icon on Actionbar
and then Use one FloatingActionButton
like this:
https://github.com/xuyisheng/DesignSupportLibraryDemo
Or i did that myself like this:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--Your content-->
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layoutdetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumbnaildetails"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:contentDescription="@string/imghd"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<TextView
android:id="@+id/txtitemdetailstitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="85dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/tbbardetails"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@drawable/ic_work"
app:backgroundTint="#E91E63"
app:fabSize="normal"
app:layout_anchor="@id/app_bar_layoutdetails"
app:layout_anchorGravity="right|bottom" />
</android.support.design.widget.CoordinatorLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With