浮动操作按钮错误
问题描述:
的com.android.support:design
库的最新更新之后,我有一个奇怪的错误:浮动操作按钮错误
预期结果是第一个。然而,大约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>
任何想法?
答
是的它是bug。对于解决方法,您可以采取以下方法。
yourView.post(new Runnable() {
@Override
public void run() {
yourView.requestLayout();
}
});
其中“yourView”是锚定视图。