Java 安卓侧导航抽屉:如何拥有这样的垂直边框和图像徽标
实际上,第二张图片是iOS导航抽屉,我想要安卓系统中的同一个抽屉,我有一个靠近它的抽屉,但不知道如何添加这样的3D munu边框,以及如何在家的上方添加图像徽标 需要此类型的导航边框,但不使用此库 play.google.com/store/apps/details?id=com.slidingmenu.example 图1- 图2-Java 安卓侧导航抽屉:如何拥有这样的垂直边框和图像徽标,java,android,xml,navigation-drawer,amslidemenu,Java,Android,Xml,Navigation Drawer,Amslidemenu,实际上,第二张图片是iOS导航抽屉,我想要安卓系统中的同一个抽屉,我有一个靠近它的抽屉,但不知道如何添加这样的3D munu边框,以及如何在家的上方添加图像徽标 需要此类型的导航边框,但不使用此库 play.google.com/store/apps/details?id=com.slidingmenu.example 图1- 图2- 在安卓系统中,它就像这个——linkedin www.learn2crack.com/wp-content/uploads/2014/06/device-20
- 在安卓系统中,它就像这个——linkedin
- 抽屉
<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>
谢谢你所需要的就是这个图书馆 它为您提供了所需的一切,即使不向xml添加任何内容 编辑: 如果您不想使用任何库,则应通过以下方式: 您的XMl应该是这样的
编辑: 对于边框,只需在res文件夹中绘制一个形状即可<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>
<?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 谢谢你的回答,但我没有使用任何第三方库,我想要一些自定义技术来实现这种垂直边界阴影。实际上,我发现只有linkedin android应用程序具有这种边界样式,在其他android应用程序或任何示例中,您的给定链接甚至没有像iOS nav中那样的样式,我理解您想要什么!!!你想让抽屉盖上视图并推视图!我正在编辑我的回答“你想让抽屉盖上视图并推视图”对不起,我不明白?<?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"/>
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); }
<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>
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);
<?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"/>