【问题标题】:How to open navigation drawer in android like the image below如何在 android 中打开导航抽屉,如下图所示
【发布时间】:2018-06-02 06:27:01
【问题描述】:

自定义android中的默认导航抽屉,如下图或从底部打开

screenshot

【问题讨论】:

    标签: android navigation-drawer drawer


    【解决方案1】:

    这里是主要的活动布局

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".NavigationDrawerExample">
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Content" />
    
    </LinearLayout>
    
    <android.support.design.widget.NavigationView
        android:layout_width="250dp"
        android:background="@android:color/transparent"
        android:layout_height="match_parent"
        android:layout_gravity="start">
    
        <include layout="@layout/nav_view" />
    
    </android.support.design.widget.NavigationView>
    

    这是navigationview.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="bottom"
    android:background="@android:color/transparent"
    android:orientation="vertical">
    
    <android.support.v7.widget.CardView
        app:cardElevation="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
     <LinearLayout
         android:gravity="center"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
    
         <ImageView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:src="@mipmap/ic_launcher" />
    
         <TextView
             android:padding="16dp"
             android:text="One"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
         <TextView
             android:padding="16dp"
             android:text="One"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
         <TextView
             android:padding="16dp"
             android:text="One"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
         <TextView
             android:padding="16dp"
             android:text="One"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
    
     </LinearLayout>
    </android.support.v7.widget.CardView>
    

    【讨论】:

    • 可能你必须删除透明阴影,否则它是使用此类设计材料的布局示例,你可以创建自己的
    【解决方案2】:

    你需要使用 SlidingRootNav 使用这个库

    compile 'com.yarolegovich:sliding-root-nav:1.1.0'
    

    这里是参考https://github.com/yarolegovich/SlidingRootNav

        new SlidingRootNavBuilder(this)
        .withMenuLayout(R.layout.menu_left_drawer)
        .inject();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多