Search code examples
androidfloating-action-button

Floating Action button Shadow issue


I am trying to add text in floating button.

<FrameLayout
        android:id="@+id/gallery_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|end"
        android:layout_marginRight="15dp"
        android:visibility="invisible">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_gallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/image_icon"
            app:backgroundTint="@color/white"
            android:layout_marginBottom="10dp"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp" />

        <com.mobile.widget.CircularTextView
            android:id="@+id/gallery_count_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_gravity="end"
            android:elevation="7dp"
            android:gravity="center"
            android:padding="1dp"
            android:textColor="@color/white" />
    </FrameLayout>

This is working fine. I can show the text of the floating button. The problem in floating button shadow is hided half. In image please note for gallery icon shadow is not showing fully. This is happening because of it is surrounded by the frame layout. Is there any other way to achieve this with the show the shadow too? Please let me any idea to resolve this.

image


Solution

  • Add android:layout_margin="10dp" inside both FloatingActionButton CircularTextView.

    <FrameLayout>
    
        <FloatingActionButton
            ...
            android:layout_margin="10dp" />
    
        <CircularTextView
            ...
            android:layout_margin="10dp" />
    </FrameLayout>
    

    I tried this on my project it's working.

    image here