【发布时间】:2019-03-27 09:00:42
【问题描述】:
我想在我的活动中翻译我在 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;
}
});
谁能帮助我或告诉我我做错了什么?我只是希望能够像上面那样翻译包含的布局。
【问题讨论】:
标签: android user-interface layout data-binding android-animation