Facebook lide slideout菜单(不使用该库) [英] Facebook lide slideout menu (Not using that library)

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

问题描述

我想在我的应用程序中有Facebook喜欢菜单。这里有很多线程,所有这些都建议使用一个实际上只是拍摄屏幕截图的图库,并将图像向右滑动,以便在左侧显示菜单,并通过一些转换来滑动图像。但是在这种情况下,右边的布局是不可点击的,因为它的图像。



但是我有另外一种方法,我有一个 已经的根布局具有菜单布局和内容布局。但根布局设置一些向左的负边距,所以它是不可见的。像这样 -





当用户按菜单按钮时,菜单布局向右滑动,根布局的左边距设置为0.所以现在我们看到的是 -





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



我想将布局与一些动画。所以当我为菜单布局和内容布局,即使我将相同的动画应用于这两个布局,动画的速度也不一样。所以我试图通过设置边距来向右/向左/向右移动ROOT LAYOUT 。但是,这样做没有什么显示在屏幕上。我在哪里错了我设置边距的方式显示在这里 -

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


解决方案

。以下是当我点击左上角的菜单按钮时使用的代码:

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

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

更新: rightLayout 的左侧和右侧的边距(如果需要),以使rightLayout不会缩小。



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



其中 width = 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 lide slideout菜单(不使用该库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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