1
// class that defines events on clicking menu button
class NaviClickListener implements OnClickListener {
    @Override
    public void onClick(View v) {
        MainFrame me = MainFrame.this;
        Context context = me;
        Animation anim;


        if(isMenuOpened){
            Log.d("On NAVICLICKLISTENER CALLED", "true");
        }else{
            Log.d("On NAVICLICKLISTENER CALLED", "false");
        }

        int w = parentLinearLayout.getMeasuredWidth();
        int h = parentLinearLayout.getMeasuredHeight();
        int left = (int) (parentLinearLayout.getMeasuredWidth() * 0.55);

        if (!isMenuOpened) {
            // anim = AnimationUtils.loadAnimation(context, R.anim.push_right_out_80);
            anim = new TranslateAnimation(0, left, 0, 0);
            mainNaviLayout.setVisibility(View.VISIBLE);
            animParams.init(left, 0, left + w, h);


        } else {
            // anim = AnimationUtils.loadAnimation(context, R.anim.push_left_in_80);
            anim = new TranslateAnimation(0, -left, 0, 0);
            animParams.init(0, 0, w, h);
        }
        anim.setDuration(400);
        anim.setAnimationListener(me);
        //Tell the animation to stay as it ended (we are going to set the app.layout 
     first than remove this property)
        anim.setFillAfter(false);


        // Only use fillEnabled and fillAfter if we don't call layout ourselves.
        // We need to do the layout ourselves and not use fillEnabled and fillAfter 
  because when the anim is finished
        // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved.
        // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does
        // work.
        // anim.setFillEnabled(true);
        // anim.setFillAfter(true);

        parentLinearLayout.startAnimation(anim);
    }
    }
  ///////////////

//about animation methods
 void layoutApp(boolean menuOut) {
        parentLinearLayout.layout(animParams.left, animParams.top,     
    animParams.right, animParams.bottom);
        //Now that we've set the app.layout property we can clear the animation, 
   flicker avoided :)
        parentLinearLayout.clearAnimation();

  }
@Override
public void onAnimationEnd(Animation animation) {
    // TODO Auto-generated method stub
    Log.d("On ANIMATIONEND CALLED", "ASDFASDFASDF");
    isMenuOpened = !isMenuOpened;
    if (!isMenuOpened) {
        mainNaviLayout.setVisibility(View.INVISIBLE);
    }
    layoutApp(isMenuOpened);
}
@Override
public void onAnimationRepeat(Animation animation) {
    Log.d("On ANIMATION repeat CALLED", "ASDFASDFASDF");
    // TODO Auto-generated method stub

}
@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

    Log.d("On ANIMATION start CALLED", "ASDFASDFASDF");
}
static class AnimParams {
    int left, right, top, bottom;

    void init(int left, int top, int right, int bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
      }
  }

////////////////////////////////////// HI,我有一个问题制作菜单栏。

它的工作原理类似于 Facebook 菜单栏-

(当我按下按钮时,会出现包含可扩展列表视图的菜单,并且主布局移动到页面的右侧)。

问题是,当我单击列表视图以展开父行(查看子行)时,

菜单消失,主布局回到主侧。

我试图弄清楚,当我使用 expandGroup() 方法强制扩展父行时,

它再次发生。

我想解决它,但我不能自己解决。请帮帮我~(对不起我的英语不好)

-> 我是通过使用 AnimationListener 实现的。

4

0 回答 0