欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

关于DrawerLayout的小问题

程序员文章站 2022-04-28 15:38:46
...

关于DrawerLayout的小问题

  • 问题描述:在开发中用作DrawerView的控件,在拖出时是附带阴影。想要取消掉;

  • 解决思路:先百度。 给出两种解决办法

drawableLayout.setScrimColor(Color.TRANSPARENT);
drawableLayout.setDrawerShadow(R.drawable.shape_transparent, GravityCompat.START);

很明显不是我遇到的,网上通常解决的是边上的灰色遮盖。

我后来翻看源码,看到Elevation,便想到这是高度的原因。再仔细找找看到了下面这些代码

/**
     * Sets the base elevation of the drawer(s) relative to the parent, in pixels. Note that the
     * elevation change is only supported in API 21 and above.
     *
     * @param elevation The base depth position of the view, in pixels.
     */
    public void setDrawerElevation(float elevation) {
        mDrawerElevation = elevation;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (isDrawerView(child)) {
                ViewCompat.setElevation(child, mDrawerElevation);
            }
        }
    }

结果显而易见了

drawableLayout.setDrawerElevation(0f);

收工

相关标签: 杂谈