我正在对片段进行过渡,并且找到了适合我需要的解决方案。在这里Fragment transition animations with BottomNavigationView
这是代码
await driver.executeScript("document.getElementById('u_0_a').click()");
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; }
无法解决,我也不知道该如何解决。
答案 0 :(得分:0)
您必须像这样在类中的函数上方定义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; }