com.android.support包中支持库中的BottomAppBar小部件具有isFabAttached标志和方法。在28.0.0-alpha1版本中,它具有公共访问权限。但在稳定版本28.0.0发布后,它不再可用。
我用于bottomAppBar.isFabAttached = false
动画分离和bottomAppBar.isFabAttached = true
垂直附加动画。但是在更新到 com.android.support:design:28.0.0 后isFabAttached
具有私有访问权限,因此动画不起作用。目前只有水平动画可用。
如何为最后一个版本的com.android.support:design:28.0.0
库制作这张图片上的 fab 按钮动画?
更新:问题解决了,我从 BottomAppBar 复制了代码并创建了一个自定义视图:android.support.design.bottomappbar包中的CustomBottomAppBar并添加了下一个代码:
public void setFabAttached(boolean attached) {
maybeAnimateAttachChange(attached);
maybeAnimateMenuView(fabAlignmentMode, attached);
this.fabAttached = attached;
}
private void maybeAnimateAttachChange(boolean targetAttached) {
if (fabAttached == targetAttached || !ViewCompat.isLaidOut(this)) {
return;
}
if (attachAnimator != null) {
attachAnimator.cancel();
}
List<Animator> animators = new ArrayList<>();
createCradleShapeAnimation(targetAttached, animators);
createFabTranslationYAnimation(targetAttached, animators);
AnimatorSet set = new AnimatorSet();
set.playTogether(animators);
attachAnimator = set;
attachAnimator.addListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
attachAnimator = null;
}
});
attachAnimator.start();
}