2017-04-04 158 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>