【问题标题】:How to make Custom NavigationDrawer or resize them in android如何在android中制作自定义导航抽屉或调整它们的大小
【发布时间】:2016-04-29 18:59:30
【问题描述】:

我想像这样在 android 中制作一个导航抽屉。无论如何调整android中默认导航栏的大小。如果可能,那么该怎么做? Navigation Drawer Should be like this

【问题讨论】:

    标签: android xml android-studio navigation-drawer


    【解决方案1】:

    我想我得到了我的解决方案。要更改导航抽屉宽度,我必须更改 android.support.design.widget.NavigationView 的宽度。现在我的代码是这样的。

    <android.support.design.widget.NavigationView android:id="@+id/nav_view"
        android:layout_width="100sp" android:layout_height="match_parent"
        android:layout_gravity="start" android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
    

    【讨论】:

      【解决方案2】:

      你可以用这个library

      <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">
      
          <io.codetail.widget.RevealFrameLayout
              android:id="@+id/conteiner_frame"
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
              <LinearLayout
                  android:id="@+id/content_overlay"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"/>
              <LinearLayout
                  android:id="@+id/content_frame"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"/>
      
              <android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar"
                  android:layout_height="wrap_content"
                  android:layout_width="match_parent"
                  android:minHeight="?attr/actionBarSize"
                  android:background="?attr/colorPrimary"/>
      
          </io.codetail.widget.RevealFrameLayout>
      
          <ScrollView
              android:id="@+id/scrollView"
              android:scrollbarThumbVertical="@android:color/transparent"
              android:layout_width="80dp"
              android:layout_height="match_parent"
              android:layout_gravity="start|bottom">
      
              <LinearLayout
                  android:id="@+id/left_drawer"
                  android:orientation="vertical"
                  android:layout_width="80dp"
                  android:layout_height="wrap_content"
                  android:divider="@android:color/transparent"
                  android:dividerHeight="0dp"
                  android:background="@android:color/transparent">
                  <!-- Layout of Drawer -->
              </LinearLayout>
          </ScrollView>
      </android.support.v4.widget.DrawerLayout>
      

      Java 代码

       private List<SlideMenuItem> list = new ArrayList<>(); \\ the list of menu items
      
      SlideMenuItem menuItem0 = new SlideMenuItem(ContentFragment.CLOSE, R.drawable.icn_close);
          list.add(menuItem0);
          SlideMenuItem menuItem = new SlideMenuItem(ContentFragment.BUILDING, R.drawable.icn_1);  \\first parameter is the id of menu item,the second is the icon resouce
          list.add(menuItem);
          SlideMenuItem menuItem2 = new SlideMenuItem(ContentFragment.BOOK, R.drawable.icn_2);
          list.add(menuItem2);
      
          viewAnimator = new ViewAnimator<>(this, list, contentFragment, drawerLayout,
      

      【讨论】:

      • 感谢您的回复,但我已经解决了。但是你能帮我制作导航抽屉项目的动画吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 2014-03-14
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 2020-11-23
      • 2020-12-08
      相关资源
      最近更新 更多