gpt4 book ai didi

java - 跟踪位置以动画 fragment 之间的过渡

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:44 25 4
gpt4 key购买 nike

我正在将过渡应用于 fragment ,并且找到了适合我的需要的解决方案。在这里Fragment transition animations with BottomNavigationView

这是代码

private boolean loadFragment(Fragment fragment, int newPosition) {
if(fragment != null) {
if(newPosition == 0) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentLayout, fragment).commit();

}
if(startingPosition > newPosition) {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right )
.replace(R.id.contentLayout, fragment).commit();

}
if(startingPosition < newPosition) {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left)
.replace(R.id.contentLayout, fragment).commit();

}
startingPosition = newPosition;
return true;
}

return false; }

startingPosition 无法解析,我不知道如何解决这个问题。

最佳答案

您必须在类中的函数上方定义startingPosition,如下所示:

int startingPosition = 0;
private boolean loadFragment(Fragment fragment, int newPosition) {
if(fragment != null) {
if(newPosition == 0) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.contentLayout, fragment).commit();

}
if(startingPosition > newPosition) {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right )
.replace(R.id.contentLayout, fragment).commit();

}
if(startingPosition < newPosition) {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left)
.replace(R.id.contentLayout, fragment).commit();

}
startingPosition = newPosition;
return true;
}

return false; }

关于java - 跟踪位置以动画 fragment 之间的过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56645877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com