我想在我的活动中翻译我在Y轴上包含的布局。如果使用数据绑定我之前可以做到但现在因为根视图我包含的布局是我不能这样做。
ConstraintLayout layout = (ConstraintLayout) mbinding.includedlayout;
我试过这个:
LayoutBottomSheetBinding bottomSheet =
LayoutBottomSheetBinding.inflate(getLayoutInflater());
bottomSheet.setViewModel(mActivityViewModel);
bottomSheet.constraintLayoutBottomSheet.setTranslationY(-300);
。它没有给出任何错误,但我的UI上没有任何反应,我只看到包含的布局,它不会向上或向下移动。我想这是指那个xml的另一个实例(不确定)。
LayoutBottomSheetBinding bottomSheet =
LayoutBottomSheetBinding.inflate(getLayoutInflater());
bottomSheet.setViewModel(mActivityViewModel);
bottomSheet.constraintLayoutBottomSheet.setTranslationY(-300);
ConstraintLayout layout = (ConstraintLayout) includedRootView
mBinding.buttonBottomSheet.setOnClickListener(v -> {
if (position == 0) {
bottomSheet.constraintLayoutBottomSheet.animate().translationY(0);
position = 1;
} else {
bottomSheet.constraintLayoutBottomSheet.animate().translationY(-300);
position = 0;
}
});
任何人都可以帮助我或告诉我我做错了什么?我只是希望能够翻译包括我在上面做的布局。
你必须开始动画:
。bottomSheet.constraintLayoutBottomSheet.animate()translationY(0)。开始();