2017-04-04 160 views
0

我在我的活动中实现了一个导航抽屉。我的应用程序的观众是老人,我希望图标非常大,占据整个抽屉高度。导航抽屉 - 只有图标很大

enter image description here

我期待有4个图标被均匀地隔开,并没有文字只是大图标。我曾尝试玩过标签:

<dimen name="design_navigation_icon_size" tools:override="true"></dimen> 

但我一直未能得到它的工作。当图标在顶部附近变得太大时,图标就会彼此重叠。这些图像似乎总是包含在页眉布局中。

回答

2

创建抽屉自定义视图和布局

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view_left" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_left" /> 

nav_header_left.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:background="@color/right_side_header_bg_color" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark" 
    android:paddingTop="@dimen/fifty" 
    android:paddingRight="@dimen/twenty" 
    android:paddingLeft="@dimen/twenty" 
    android:orientation="vertical" 
    android:weightSum="4"> 

    <TextView 
     android:id="@+id/add_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Gallery" 
     android:drawableLeft="@android:drawable/ic_menu_gallery" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="1" 
     /> 
    <TextView 
     android:id="@+id/gall_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Gallery" 
     android:drawableLeft="@android:drawable/ic_menu_gallery" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="1" 
     /> 
    <TextView 
     android:id="@+id/menu_add_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:text="Gallery" 
     android:drawableLeft="@android:drawable/ic_menu_add" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="1" 
     /> 

    <TextView 
     android:id="@+id/media_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:drawableLeft="@android:drawable/ic_media_rew" 
     android:gravity="center" 
     android:text="Gallery" /> 
    </LinearLayout> 
+0

似乎没有工作。所有图标捆绑在顶部 – user2924127

+0

这是我的drawerlayout: user2924127

+0

所有图标都压扁int header header。它看起来像所有的图标都试图适应该标题。 – user2924127

0

使用此代码navigationView:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start" 
android:theme="@style/AppTheme"> 

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@android:color/white" 
      android:titleTextColor="@color/theme_color_dark" 
      style="@style/AppTheme" 
      android:theme="@style/AppTheme"/> 

    </android.support.design.widget.AppBarLayout> 

</android.support.design.widget.CoordinatorLayout> 
<fragment 
    android:id="@+id/menu_fragement" 
    android:tag="Menu" 
    android:layout_width="250dp" 
    android:layout_gravity="start" 
    android:name="com.app.medcallz.fragments.MenuFragement" 
    android:layout_height="match_parent" 
    /> 
</android.support.v4.widget.DrawerLayout> 

MenuFragment:

<LinearLayout 
android:id="@+id/options_container" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:layout_below="@+id/user_detail_container"> 

    <ImageView 
     android:id="@+id/notificationsIcon" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/nav_notificatios" 
     android:layout_weight="0.1"/> 

    <View 
     android:id="@+id/account_divider" 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/login_divider_width" 
     android:background="@color/white_color" 
     android:visibility="visible" 

     /> 
</LinearLayout>