【问题标题】:Floating Action Button bug in com.android.support:design:24.2.1com.android.support:design:24.2.1 中的浮动操作按钮错误
【发布时间】:2016-10-22 08:04:08
【问题描述】:

com.android.support:design库最新更新后,出现了一个奇怪的bug:

预期的结果是第一个。然而,大约 40% 的时间,FAB 会忽略锚点。 这也发生在设计支持库的新 25.0.0 版本中。

这里是布局:

<?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>

有什么想法吗?

【问题讨论】:

    标签: android android-layout floating-action-button android-support-design


    【解决方案1】:

    是的,它是bug。对于解决方法,您可以按照以下方式进行。

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

    其中“yourView”是锚定视图。

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 2020-08-31
      • 2020-03-25
      相关资源
      最近更新 更多