android - 如何更改自定义滑动菜单的导航

标签 android slidingmenu android-sliding

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

所以基本上我正在尝试打开滑动菜单并且它正在打开从左到右 现在我想改变它的方向从从右到左。我该怎么做。

下面是我的代码。

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

enter image description here

所以基本上你可以在上图中看到我的菜单是从从左到右打开的,我怎样才能将它从从右到左更改。

提前谢谢你。

最佳答案

我已经解决了这个问题,我刚刚将重力更改为下面这条线的右侧,现在可以使用了。

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);

谢谢大家对我的帮助。

关于android - 如何更改自定义滑动菜单的导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22165663/

相关文章:

java - 将 strings.xml 中的数组添加到另一个 ArrayList

javascript - onclick 事件在手机间隙 android 中不起作用

android - 如何将阴影调整为 RTL SlidingMenu

android - 更改 SlidingDrawer handle 的对齐方式(左、右等)

android - 单击面板外部时如何隐藏 Umano SlidingupPanel

android - 从 adb 向 BroadcastReceiver 发送 Intent

android - Robolectric 由于调用存储而从 NullPointerException 失败

android - 如何在滑动菜单中使用 Android Google Map V2 作为 fragment ?

android - SlidingMenu 和三星在弹出 View 中打开(指定的 child 已经有 parent 。异常(exception))

android - 为 SlidingMenu 创建 jar 文件