如何翻译活动中包含的布局



我想在我的活动中翻译我在 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(.start((;

最新更新