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

时间:2019-03-27 09:00:42

标签: android user-interface layout data-binding android-animation

我想在我的活动中在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;
        }
    });

有人可以帮助我还是告诉我我做错了什么?我只希望能够像上面的im一样翻译包含的布局。

1 个答案:

答案 0 :(得分:0)

您必须开始动画:

bottomSheet.constraintLayoutBottomSheet.animate()。translationY(0).start();

相关问题