Blodhgard
Blodhgard

Reputation: 9385

Floating Action Button bug in com.android.support:design:24.2.1

After the latest update of the com.android.support:design library, I have a weird bug:

Correct behavihour

Bug

The expected results is the first one. However, around the 40% of the times, the FAB ignore the anchor. This happens also in the new 25.0.0 version of the design support library.

Here the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_gravity="center"
android:background="@color/black_semi_transparent"
android:clickable="true"
android:orientation="vertical"
android:baselineAligned="false">

<Button
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:background="@android:color/transparent"
    android:onClick="onBackPressed" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="12"
    android:baselineAligned="false"
    android:orientation="horizontal">

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:onClick="onBackPressed" />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="18" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/linearlayout_anchor"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:background="@color/red_primary_color"
                android:orientation="vertical" >

                ...

            </LinearLayout>

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="6"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:baselineAligned="false">

                    ...

                </LinearLayout>
            </ScrollView>
        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:clickable="true"
            android:src="@drawable/ic_more_vert_white_36dp"
            app:layout_anchor="@id/linearlayout_anchor"
            app:layout_anchorGravity="bottom|right|end"/>

    </android.support.design.widget.CoordinatorLayout>

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:onClick="onBackPressed" />

</LinearLayout>

<Button
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:background="@android:color/transparent"
    android:onClick="onBackPressed" />

</LinearLayout>

Any idea?

Upvotes: 2

Views: 395

Answers (1)

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20910

Yes it is bug. for the workaround you can do following way.

yourView.post(new Runnable() {
    @Override
    public void run() {
        yourView.requestLayout();
    }
});

where "yourView" is the anchored view.

Upvotes: 1

Related Questions