關於DrawerLayout的小問題

qq_36861770發表於2018-08-16

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

收工

相關文章