Facebook的立德滑出式菜单(不使用该库) [英] Facebook lide slideout menu (Not using that library)

查看:176
本文介绍了Facebook的立德滑出式菜单(不使用该库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有像Facebook的菜单中的我的应用程序。上有这么多线程和所有的人都建议使用一个库,实际上只需要在屏幕的截屏和滑动向右,以显示在左侧和幻灯片图像与一些过渡菜单图像。但在这种情况下,在右边的布局并不因为其图像可点击

不过,我有一些做的另一种方式,我有一个根布局其中有菜单布局和内容布局。但根布局设置一定的负面利润率向左所以它是不可见的。这样的 -

当用户presses菜​​单按钮,菜单布局滑动到右侧和根布局的左页边距设置为0。所以,现在我们看到的是这样的 -

现在,真正的问题从这里开始

我想幻灯片都与一些动画的布局。所以,当我在动画菜单布局和放大器;内容布局,动画两个布局是不一样的速度,甚至如果我在同样的动画吧。所以,我想为移根布局仅向右/设置保证金为它留下。但在这样做没有任何显示在屏幕上。我要去哪里错了。我设置保证金的方式显示在这里 -

  INT宽度= leftLayout.getWidth();
!isLayoutShown = isLayoutShown;
如果(isLayoutShown){
    rootLayoutParams.setMargins(0,0,0,0);
    rootLayout.setLayoutParams(rootLayoutParams);
}其他{
    rootLayoutParams.setMargins(-width,0,0,0);
    rootLayout.setLayoutParams(rootLayoutParams);
}
 

解决方案

最后,不知为什么我能做到这一点。下面是用来当我点击菜单按钮,在左上角的code:

  @覆盖
公共无效的onClick(视图v){
rootLayoutParams =新的LayoutParams(rightLayout.getWidth()
    rightLayout.getHeight());

如果(lhsMenu.getVisibility()== View.GONE){
    lhsMenu.setVisibility(View.VISIBLE);
    动画slideRight = setRightSlidingAnimation();
    rightLayout.setAnimation(slideRight);
    lhsMenu.setAnimation(slideRight);
} 其他 {
    动画slideLeft = setLeftSlidingAnimation();
    rightLayout.setAnimation(slideLeft);
    lhsMenu.setAnimation(slideLeft);
    lhsMenu.setVisibility(View.GONE);
    }
}
 

更新:同时设置保证金为左,右(如果​​需要) rightLayout 这样的rightLayout不会缩水

_rightLayoutParams.setMargins(宽度,0, - 宽度,0)

其中,宽度= 200 在我的情况。

I want to have facebook like menu in my application. There are many threads on this and all of them suggest to use a library which actually just takes a screenshot of the screen and slides that image towards right so as to show menu on left hand side and slide image with some transition. But in that case, the layout on the right is not clickable since its an image.

But I have some another way of doing it in which I have a Root Layout which already has Menu Layout and Content Layout. But root layout is set some negative margin towards left so it is not visible. Like this-

When user presses menu button, the Menu Layout is slid to the right and root layout's left margin is set to 0. So now what we see is this-

Now, The real problem starts here

I want to slide both the layouts with some animation. So when I animate the Menu layout & Content Layout, the animation for both the layouts is not at same speed even if I am applying same animation to it. So I tried to Shift ROOT LAYOUT only towards right/left by setting margin to it. But on doing so nothing is shown on the screen. Where am I going wrong. The way I set margin is shown here-

int width = leftLayout.getWidth();
isLayoutShown = !isLayoutShown;
if(isLayoutShown){
    rootLayoutParams.setMargins(0, 0, 0, 0);
    rootLayout.setLayoutParams(rootLayoutParams);    
}else{
    rootLayoutParams.setMargins(-width, 0, 0, 0);
    rootLayout.setLayoutParams(rootLayoutParams);
}

解决方案

Finally somehow I could do it. Here's the code used when I click on the menu button on the left top corner:

@Override
public void onClick(View v) {
rootLayoutParams = new LayoutParams(rightLayout.getWidth(),
    rightLayout.getHeight());

if (lhsMenu.getVisibility() == View.GONE) {
    lhsMenu.setVisibility(View.VISIBLE);
    Animation slideRight = setRightSlidingAnimation();
    rightLayout.setAnimation(slideRight);
    lhsMenu.setAnimation(slideRight);
} else {
    Animation slideLeft = setLeftSlidingAnimation();
    rightLayout.setAnimation(slideLeft);
    lhsMenu.setAnimation(slideLeft);
    lhsMenu.setVisibility(View.GONE);
    }
}

Update: Also set margin to left and right (if needed) of rightLayout so that the rightLayout will not shrink.

_rightLayoutParams.setMargins(width, 0, -width, 0);

where width = 200 in my case.

这篇关于Facebook的立德滑出式菜单(不使用该库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆