Android side navigation drawer : 如何有这样的垂直边框和图像标志

Android side navigation drawer : how to have such vertical border and image logo

帮助我实际上 2ND 图像是 iOS 导航抽屉,我想要 android 中的相同抽屉,我有一个靠近它的抽屉但不知道如何添加这样的 3D munu 边框并在 HOME

上方添加图像徽标

Want this type of NAV border but without using this Lib

play.google.com/store/apps/details?id=com.slidingmenu.example

图片 1 - had made this navigation drawer

图 2 - i want such navigation border

www.learn2crack.com/wp-content/uploads/2014/06/device-2014-06-06-120657.png

我正在使用这样的代码

mDrawerLayout.setDrawerShadow(R.drawable.layerlist,GravityCompat.START);

MAIN_ACTIVITY Code

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    FrameLayout mainView;
mainView = (FrameLayout) findViewById(R.id.frame_container);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.overflow_icon, // nav menu toggle icon
                R.string.app_name, // nav drawer open - description for
                                    // accessibility
                R.string.app_name // nav drawer close - description for
                                    // accessibility
        ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);


                float xPositionOpenDrawer = mDrawerList.getWidth();
                float xPositionWindowContent = (slideOffset * xPositionOpenDrawer);
                mainView.setX(xPositionWindowContent);

            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        if (savedInstanceState == null) {
            // on first time display view for first nav item
            displayView(0);
        }

谢谢

你只需要这个图书馆

https://github.com/mikepenz/MaterialDrawer

它为您提供所需的一切,甚至无需向您的 xml 添加任何内容。

编辑:

如果你不想使用任何库,你应该这样做:

你的XMl应该是这样的

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent" >

    <android.support.v7.widget.Toolbar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/view" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--PUT YOUR VIEW HERE-->

    </RelativeLayout>
</LinearLayout>
<RelativeLayout
    android:layout_width="240dp"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#CFCFCF"
        android:dividerHeight="1dp"/>
    <FrameLayout
        android:layout_width="5dp"
        android:layout_height="match_parent"
        android:background="@drawable/MY_GRADIANT_BACKGROUND"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

注意两点! 1.做一个渐变背景放在列表上方的框架布局上 2.我用了工具栏!因此请注意清单中的 activity 主题并使用 NOACTIONBAR。

在您的 activity 中,您应该处理抽屉滑动并在抽屉滑动时滑动 MAIN VIEW:

mDrawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.drawer_button, R.string.app_name, R.string.app_name)
    {
        @SuppressLint("NewApi")
        public void onDrawerSlide(View drawerView, float slideOffset)
        {
            float moveFactor;
                moveFactor = -(drawerView.getWidth() * slideOffset);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            {
               ((View)findViewById(R.id.frame_container)).setTranslationX(moveFactor);
            }
            else
            {
                TranslateAnimation anim = new TranslateAnimation(lastTranslate, moveFactor, 0.0f, 0.0f);
                anim.setDuration(0);
                anim.setFillAfter(true);
                ((View)findViewById(R.id.content_frame)).startAnimation(anim);

            }
            lastTranslate = moveFactor;
        }

    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

编辑:

对于边框,只需在您的 res 文件夹中绘制一个形状

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="linear"
    android:angle="180"
    android:startColor="#50666666"
    android:endColor="#10444444"/>

并将其作为列表上方小框架布局的背景。关注我的XML !!!!