Android:ExtendedFloatingActionButton .shirk() 不起作用
Android: ExtendedFloatingActionButton .shirk() does not work
我正在使用 com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
并尝试通过调用 .shrink()
来缩小该按钮,但没有任何反应。
这是我的按钮xml:
<androidx.coordinatorlayout.widget.CoordinatorLayout ... >
...
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/exploring_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="-24dp"
android:text="Start Exploring"
app:layout_anchor="@+id/bottom_sheet"
app:layout_anchorGravity="top|end"
app:icon="@drawable/ic_walking" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的片段代码:
Log.d(TAG, "shrinking start")
binding.exploringBtn.shrink(object :
ExtendedFloatingActionButton.OnChangedCallback() {
override fun onShrunken(extendedFab: ExtendedFloatingActionButton?) {
super.onShrunken(extendedFab)
Log.d(TAG, "onShrunken: ")
}
override fun onExtended(extendedFab: ExtendedFloatingActionButton?) {
super.onExtended(extendedFab)
Log.d(TAG, "onExtended: ")
}
})
Log.d(TAG, "shrinking end")
我的 logcat 输出(证明在我执行 .shrink()
方法两次但没有任何反应后):
2021-07-13 20:28:41.453 17098-17098/uk.co.explorer D/kesD: listenForPathData: isExploring: true
2021-07-13 20:28:41.454 17098-17098/uk.co.explorer D/kesD: shrinking start
2021-07-13 20:28:41.465 17098-17098/uk.co.explorer D/kesD: shrinking end
2021-07-13 20:28:42.089 17098-17098/uk.co.explorer D/kesD: checkIfNeedToRequestPermissions: need to request permissions: false
2021-07-13 20:28:53.917 17098-17098/uk.co.explorer D/kesD: listenForPathData: isExploring: true
2021-07-13 20:28:53.918 17098-17098/uk.co.explorer D/kesD: shrinking start
2021-07-13 20:28:53.922 17098-17098/uk.co.explorer D/kesD: shrinking end
我的 gradle material 依赖项看起来像:
implementation 'com.google.android.material:material:1.4.0'
为了解决这个问题,我只是将 ExtendedFloatingActionButton
包裹在 LinearLayout
中。不是最优的,但解决了这个问题。我相信问题可能与我在同一屏幕中的底部 sheet 布局有关。现在的代码如下:
<LinearLayout
android:id="@+id/extend_btn_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/bottom_sheet"
app:layout_anchorGravity="top|end"
android:elevation="4dp">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/exploring_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Start Exploring"
app:icon="@drawable/ic_walking" />
</LinearLayout>
我正在使用 com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
并尝试通过调用 .shrink()
来缩小该按钮,但没有任何反应。
这是我的按钮xml:
<androidx.coordinatorlayout.widget.CoordinatorLayout ... >
...
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/exploring_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="-24dp"
android:text="Start Exploring"
app:layout_anchor="@+id/bottom_sheet"
app:layout_anchorGravity="top|end"
app:icon="@drawable/ic_walking" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的片段代码:
Log.d(TAG, "shrinking start")
binding.exploringBtn.shrink(object :
ExtendedFloatingActionButton.OnChangedCallback() {
override fun onShrunken(extendedFab: ExtendedFloatingActionButton?) {
super.onShrunken(extendedFab)
Log.d(TAG, "onShrunken: ")
}
override fun onExtended(extendedFab: ExtendedFloatingActionButton?) {
super.onExtended(extendedFab)
Log.d(TAG, "onExtended: ")
}
})
Log.d(TAG, "shrinking end")
我的 logcat 输出(证明在我执行 .shrink()
方法两次但没有任何反应后):
2021-07-13 20:28:41.453 17098-17098/uk.co.explorer D/kesD: listenForPathData: isExploring: true
2021-07-13 20:28:41.454 17098-17098/uk.co.explorer D/kesD: shrinking start
2021-07-13 20:28:41.465 17098-17098/uk.co.explorer D/kesD: shrinking end
2021-07-13 20:28:42.089 17098-17098/uk.co.explorer D/kesD: checkIfNeedToRequestPermissions: need to request permissions: false
2021-07-13 20:28:53.917 17098-17098/uk.co.explorer D/kesD: listenForPathData: isExploring: true
2021-07-13 20:28:53.918 17098-17098/uk.co.explorer D/kesD: shrinking start
2021-07-13 20:28:53.922 17098-17098/uk.co.explorer D/kesD: shrinking end
我的 gradle material 依赖项看起来像:
implementation 'com.google.android.material:material:1.4.0'
为了解决这个问题,我只是将 ExtendedFloatingActionButton
包裹在 LinearLayout
中。不是最优的,但解决了这个问题。我相信问题可能与我在同一屏幕中的底部 sheet 布局有关。现在的代码如下:
<LinearLayout
android:id="@+id/extend_btn_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/bottom_sheet"
app:layout_anchorGravity="top|end"
android:elevation="4dp">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/exploring_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Start Exploring"
app:icon="@drawable/ic_walking" />
</LinearLayout>