3

我正在尝试我的自定义滑动导航。我知道已经有很多教程或库可用,但这是出于我自己的目的。

所以基本上我正在尝试打开滑动菜单,left to right现在它正在打开我想改变它的方向right to left。我怎样才能做到这一点。

下面是我的代码。

public class Profile extends Activity implements OnClickListener {

    private int windowWidth;
    boolean alreadyShowing = false;
    private Animation mAnimation;
    LayoutInflater mLayoutInflater;
    private RelativeLayout mRelativeLayout;

    ImageView sliding_menu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);

        Display display = getWindowManager().getDefaultDisplay();
        windowWidth = display.getWidth();
        display.getHeight();
        mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        sliding_menu = (ImageView) findViewById(R.id.slidingMenu);
        sliding_menu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                if (!alreadyShowing) {
                    alreadyShowing = true;
                    openSlidingMenu();
                }
            }
        });
    }

    private void openSlidingMenu() {

        int width = (int) (windowWidth * 0.8f);
        translateView((float) (width));
        int height = LayoutParams.FILL_PARENT;
        final View layout = mLayoutInflater.inflate(R.layout.settings,
                (ViewGroup) findViewById(R.id.setting));

        final PopupWindow optionsPopup = new PopupWindow(layout, width, height,
                true);
        optionsPopup.setBackgroundDrawable(new PaintDrawable());
        optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
        optionsPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            public void onDismiss() {
                cleanUp();
                translateView(0);
                cleanUp();
                alreadyShowing = false;
            }
        });
    }

    private void translateView(float right) {
        mAnimation = new TranslateAnimation(0f, right, 0f, 0f);
        mAnimation.setDuration(100);
        mAnimation.setFillEnabled(true);
        mAnimation.setFillAfter(true);

        mRelativeLayout = (RelativeLayout) findViewById(R.id.profile);
        mRelativeLayout.startAnimation(mAnimation);
        mRelativeLayout.setVisibility(View.VISIBLE);
    }

    private void cleanUp() {
        if (null != mRelativeLayout) {
            mRelativeLayout.clearAnimation();
            mRelativeLayout = null;
        }
        if (null != mAnimation) {
            mAnimation.cancel();
            mAnimation = null;
        }
    }

在此处输入图像描述

所以基本上你可以在上图中看到我的菜单正在打开,我left to right该如何更改它right to left

先感谢您。

4

1 回答 1

2

我已经解决了这个问题,我刚刚将重力改变到下面这条线的右侧,它现在正在工作。

optionsPopup.showAtLocation(layout, Gravity.RIGHT, 0, 0);

所以在改变我的代码之前是这样的。

final PopupWindow optionsPopup = new PopupWindow(layout, width, height,true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);

现在就像下面

final PopupWindow optionsPopup = new PopupWindow(layout, width, height,true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.RIGHT, 0, 0);

谢谢大家帮助我。

于 2014-03-04T09:59:53.590 回答