0

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

想要这种类型的 NAV 边框但不使用这个 Lib

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

图 1 - 制作了这个导航抽屉

图 2 - 我想要这样的导航边框

  • 在 android 中就是这样的 -linkedin

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

我正在使用这样的代码

  • 抽屉

    <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">
    
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:background="@drawable/layerlist"
        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"    
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>
    </android.support.v4.widget.DrawerLayout>
    
  • 添加边框

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

  • R.drawable.layerlist

    <?xml version="1.0" encoding="utf-8"?>
    

    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <gradient
                android:endColor="#BFBFBF"
                android:startColor="#EDEDED"
                 />
        </shape>
    </item>
    <item android:right="15dp">
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle" >
            <solid android:color="#FFFFFF" />
        </shape>
    </item>
    

  • 列表选择器

    <?xml version="1.0" encoding="utf-8"?>
    

    <item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
    <item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>
    

MAIN_ACTIVITY 代码

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

谢谢

4

1 回答 1

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. 我使用了工具栏!因此,请注意清单中的活动主题并使用 NOACTIONBAR 主题。

在您的活动中,您应该处理抽屉滑动并在抽屉滑动时滑动主视图:

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 !!!

于 2016-03-07T13:07:30.167 回答