Parent Activity's code getting executed, but the result (animation) is not showing up

前端 未结 1 762
刺人心
刺人心 2021-01-26 13:48

I want to have a sliding menu throughout my application which will be accessible for every activity in my application. For this, I created a parent activity to which all other a

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 14:16

    Problem solved, just had to initialize the view once again in onOptionsItemSelected since the right layout has changed now. The method now looks like:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
    
        _rootLayout = (RelativeLayout) findViewById(R.id.rl_root);
        _leftLayout = (RelativeLayout) findViewById(R.id.ll_lhs_menu);
        _rightLayout = (RelativeLayout) findViewById(R.id.rl_right);
    
        _leftLayout.setVisibility(View.VISIBLE);
        int width = _leftLayout.getWidth();
        if (width == 0) {
            width = 300;
        }
    
    if (!isMenuVisible()) {
        Toast.makeText(this, "Executed successfully...", Toast.LENGTH_LONG).show();
        _leftLayout.setVisibility(View.VISIBLE);
    
        _rightLayoutParams = new LayoutParams(
            _rightLayout.getWidth(), _rightLayout.getHeight());
        _rightLayoutParams.setMargins(width, 0, -width, 0);
        _rightLayout.setLayoutParams(_rightLayoutParams);
    
        Animation slideRight = setRightSlidingAnimation();
        _leftLayout.startAnimation(slideRight);
        _rightLayout.startAnimation(slideRight);
    } else {
        Animation slideLeft = setLeftSlidingAnimation();
        _rightLayout.startAnimation(slideLeft);
        _leftLayout.startAnimation(slideLeft);
    }
    
    setMenuVisible(!isMenuVisible());
    break;
    }
    return false;
    }
    

    0 讨论(0)
提交回复
热议问题