【问题标题】:Bug with anchored FloatingActionButton in support library 24.2.1支持库 24.2.1 中锚定 FloatingActionButton 的错误
【发布时间】:2017-01-28 17:27:49
【问题描述】:

我从 24.2.0 开始就一直有这个问题,但现在我使用的是 24.2.1 并且错误仍然存​​在,它只运行良好

我有一个锚定的 FloatingActionButton,如下所示:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/contact_coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="es.cocode.baseapp.contact.ContactFragment">

        <FrameLayout
            android:id="@+id/map_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="198dp"
            android:layout_marginBottom="210dp">

            <fragment
                android:id="@+id/map_fragment"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_fullscreen_map"
            android:src="@drawable/ic_fullscreen_white_48dp"
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:layout_margin="@dimen/fab_margin"
            app:layout_anchor="@id/map_fragment_container"
            app:layout_anchorGravity="bottom|end" />

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

</ScrollView>

它通常是这样工作的:

但有时会出现bug,锚点不起作用:

有没有办法解决这个问题,或者我应该等到这个错误得到修复并改用 24.1.1 吗?

【问题讨论】:

  • CoordinatorLayoutScrollView 内?尝试在 ScrollView 中仅包装可滚动内容(FrameLayout)。
  • 所有都是“可滚动内容”(FAB 之后我有一个包含标签,其布局包含地点、电话、邮件和网站)。
  • 同样的事情发生在我身上。大多数时候,晶圆厂的锚重力工作正常,但有时不能,导致您所描述的情况。哦,好吧,现在恢复...
  • @JoaoSousa 我已经发布了答案。
  • 就我而言,我什至没有地图,但我知道这可能是由于布局中的测量变化而发生的。我真的不想连接听众并控制晶圆厂的知名度,但也许我在这里别无选择。

标签: android android-support-library android-design-library androiddesignsupport floating-action-button


【解决方案1】:

标记为已修复 问题已修复并在 26.0.0 版本的支持库中发布。

【讨论】:

    【解决方案2】:

    至于 2017 年 5 月 2 日(25.3.1),该错误仍未修复。在尝试了所有解决方案后,唯一对我有用的是:

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

    yourView 是锚定视图。

    【讨论】:

    • Xamarin.Android 中使用的解决方案并修复问题。非常感谢。
    【解决方案3】:

    我的朋友还有另一种方法可以使用最新的支持库而不是使用任何其他东西。

    就用这个吧-

    <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:src="@drawable/ic_add"
            android:layout_gravity="center_vertical|center_horizontal"
            app:layout_anchor="@+id/appBar"
            app:layout_anchorGravity="bottom|right" />
    

    【讨论】:

    • 你能解释一下这个答案吗?
    • 老实说兄弟。我通过在设计部分拖动 FAB 得到了这个答案。即使我更改 AppBar 高度,它也能完美运行。
    【解决方案4】:

    解决方案是在 XML 中将 FloatingActionButton 可见性设置为 GONE,并在地图准备好后将其设置回 VISIBLE

    @Override
    public void onMapReady(GoogleMap googleMap) {
        . . .
        yourFAB.setVisibility(View.VISIBLE);
    }
    

    编辑:这是bug 的解决方法。

    【讨论】:

    • 提供的链接对我有帮助,该链接中提供的#7 答案对我有用
    【解决方案5】:

    Bug reported 并希望尽快修复。请给它加星标。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 2016-04-16
      • 2015-10-01
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多