0

I can able to make a card view with a fab button. I can anchor the fab button in card view but here I want to make a card view which will look like BottomAppBar (Material designing).

Code

 <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".fragments.ViewHistoryFragment"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        style="@style/Widget.MaterialComponents.BottomAppBar">

    <!--    style="@style/Widget.MaterialComponents.BottomAppBar"-->

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/Widget.MaterialComponents.CardView">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="#C3EFC2">


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="sdfkjgasdfjasdf"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="sdfkjgasdfjasdf"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="sdfkjgasdfjasdf"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="sdfkjgasdfjasdf"/>


            </LinearLayout>

        </com.google.android.material.card.MaterialCardView>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_anchor="@id/cv"
            android:src="@mipmap/ic_launcher"
            android:layout_marginEnd="@dimen/margin8"
           app:layout_anchorGravity="bottom|right|end"
            app:borderWidth="@dimen/margin8"
            app:backgroundTint="#343433" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

I want to like this type of cut It means I want that cradle diameter in mine card view. attached my wanted output

Any suggestion of anyone will be appreciated.

BlackBlind
  • 772
  • 9
  • 26

1 Answers1

3

You can apply to the MaterialCardView an EdgeTreatment:

    BottomAppBarTopEdgeTreatment bottomAppBarTopEdgeTreatment = new BottomAppBarTopEdgeTreatment(
            fabMargin),
            roundedCornerRadius,
            cradleVerticalOffset
    );
    bottomAppBarTopEdgeTreatment.setFabDiameter(fabSize);

    MaterialCardView cardView = findViewById(R.id.card);
    cardView.setShapeAppearanceModel( cardView.getShapeAppearanceModel().toBuilder()
            .setTopEdge(bottomAppBarTopEdgeTreatment)
            .build());        

Then just anchor the Fab to the CardView:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    app:layout_anchorGravity="top|center"
    app:layout_anchor="@id/card"
    .../>

<com.google.android.material.card.MaterialCardView
    android:id="@+id/card"
    ../>

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841