How I can remove the unnecessary top padding of the Navigation view?

浪尽此生 提交于 2019-12-17 06:08:25

问题


There's an unnecessary top padding between the header and the first item shown in this picture.

How it can be removed?

you can find the source code here: https://github.com/chrisbanes/cheesesquare


回答1:


NavigationView seeks to match the material design specs for the navigation drawer which state an 8dp space between content areas. Generally there are no ways to override NavigationView to specifically break the specifications.




回答2:


You can override predefined dimensions at your dimens.xml as;

<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen>

Other possible values are here: https://github.com/android/platform_frameworks_support/blob/master/design/res/values/dimens.xml




回答3:


You should read the Ian's answer. The NavigationView follows the Material guidelines and you should not break these specs.

However, currently, you can override this value in your project.

Just add to your dimens.xml:

<dimen name="design_navigation_separator_vertical_padding">0dp</dimen>

Warning:

  • in the future the Android Team can change this value!
  • the same value is applied to each separator in the list

The NavigationView uses a LinearLayout as header view. You can see this layout in the source code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingBottom="@dimen/design_navigation_separator_vertical_padding" />



回答4:


very simple step : add the following attribute to your base application theme (stylename=AppTheme) Style.xml :

        <item name="listPreferredItemHeightSmall">18dp</item>



回答5:


This is answered here Gabriele's answer

Just add to your dimens.xml:

<dimen name="design_navigation_separator_vertical_padding">0dp</dimen>



来源:https://stackoverflow.com/questions/30584554/how-i-can-remove-the-unnecessary-top-padding-of-the-navigation-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!