简体   繁体   English

Android中的自定义导航抽屉

[英]Custom navigation drawer in android

I have a requirement, where when the navigation drawer slides open, it should appear to be below the Main Activity with portion of the Main Activity being visible at the right and appear on top of the drawer. 我有一个要求,当导航抽屉滑动打开时,它应该显示在Main Activity(主活动)下方,Main Activity(主活动)的一部分在右侧可见,并显示在抽屉顶部。 I am able to this achieve partially using scaling. 我能够使用缩放来部分实现这一目标。 But the navigation drawer beneath the Main Activity is not coming. 但是主活动下面的导航抽屉没有出现。 Is there any way to achieve this. 有什么办法可以做到这一点。 Below is my code. 下面是我的代码。

 public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
                final float diffScaledOffset = slideOffset*(1 - 0.9f);
                final float offsetScale = 1 - diffScaledOffset;
                contentView.setScaleX(offsetScale);
                contentView.setScaleY(offsetScale);
                final float xOffset = drawerView.getWidth()* slideOffset;
                final float xOffsetDiff = contentView.getWidth() * diffScaledOffset / 2;
                final float xTranslation = xOffset - xOffsetDiff;
                contentView.setTranslationX(xTranslation);
            }

Sample image 样本图片

Sample image 样本图片

public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
                int width = getResources().getDimensionPixelSize(R.dimen.navigation_view_width);
                float moveFactor = (width * slideOffset);
                contentView.setTranslationX(moveFactor);
            }

try this , i think it will help 试试这个,我认为这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM