跟踪位置以动画化片段之间的过渡

时间:2019-06-18 09:26:22

标签: java android android-fragments android-animation

我正在对片段进行过渡,并且找到了适合我需要的解决方案。在这里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; } 无法解决,我也不知道该如何解决。

1 个答案:

答案 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; }