【发布时间】:2017-09-09 11:52:00
【问题描述】:
所以我有一个浮动操作按钮,它锚定到底部工作表布局。然后我单击一个按钮,将底部工作表的状态设置为 STATE_HIDDEN。底部工作表正确隐藏并弹出一个小吃栏,浮动操作按钮相应上升。问题是在 Snackbar 关闭并且浮动操作按钮下沉后:当我将底部工作表的状态设置回 STATE_COLLAPSED 时,浮动操作按钮需要一秒或 2 秒才能重新调整并锚回到底部工作表(最后一个屏幕截图) .如何消除延迟?谢谢:)
问题图片
按钮代码:
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
final Snackbar mySnackbar
= Snackbar.make(findViewById(R.id.bottom_sheet_page),
R.string.map_undoremove, Snackbar.LENGTH_LONG);
mySnackbar.setAction(R.string.undo_string, new View.OnClickListener(){
@Override
public void onClick(View v) {
mWaypoint = mMap.addMarker(new MarkerOptions().position(mWaypoint.getPosition())
.title("Test"));
}
});
mySnackbar.show();
布局代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottom_sheet_page"
tools:context=".Map.MapNavDrawer" >
<!-- Your content -->
<include layout="@layout/activity_maps" />
<!-- Bottom Sheet -->
<LinearLayout
android:clickable="true"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="16dp"
app:behavior_hideable="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
>
<TextView
android:id="@+id/textViewWaypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_waypointtitle"
android:textStyle="bold"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/textViewLocName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textStyle="italic"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/textViewLocDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@android:color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|end"
android:orientation="horizontal">
<Button
android:id="@+id/button2"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:drawableTop="@drawable/ic_edit_black_24dp"
android:onClick="selectPlace"
android:text="@string/map_editwaypoint" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:drawableTop="@drawable/ic_delete_black_24dp"
android:onClick="deleteWaypoint"
android:text="@string/map_removewaypoint" />
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="@string/map_sharewaypoint"
android:drawableTop="@drawable/ic_menu_share"
style="?android:attr/buttonBarButtonStyle"/>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/map_marker_radius"
android:tint="@android:color/white"
app:layout_anchor="@id/bottom_sheet"
app:layout_anchorGravity="top|end"
tools:ignore="VectorDrawableCompat" />
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
可能复活死者,但是,你有没有设法妥善处理这个问题?海拔对我不起作用,而且将 Snackbar 放在顶部也不是一个选项。我尝试它只是为了看看效果,它基本上是把按钮放在屏幕顶部!
-
哈哈是的哇,这是很久以前的事了。实际上,当小吃店启动时,我也最终隐藏了按钮。关闭小吃店后,我再次呈现按钮。不完全是我想要的,但最终修复了按钮的错误。
-
我明白了。我现在实际上想出了相同的解决方案。我试图再次强制布局设置,但没有运气。我想如果我们需要一个真正的解决方案,我们需要使用协调器布局行为。
标签: android android-layout floating-action-button bottom-sheet