简体   繁体   English

具有内部间距的Android NavigationView

[英]Android NavigationView with internal spacing

I am currently developing an Android App with a support NavigationView. 我目前正在开发一个支持NavigationView的Android应用程序。 I have to question to make it as I want it: (1) I want to divide the navigation elements into two areas: one at top below the header and one at the bottom end. 我不得不质疑我想要它:(1)我想将导航元素分成两个区域:一个位于标题下方,一个位于底端。 (2) I want to remove the padding between the divider and the element below it. (2)我想删除分隔符和它下面的元素之间的填充。

How it looks vs how it should look: 它看起来如何看起来应该如何: 它的外观与它的外观

I know there is a way to override the padding value, which would fix (2). 我知道有一种方法可以覆盖填充值,这将修复(2)。 But this feels kind of dirty and maybe there is another approach to achieve both of this. 但这感觉有点脏,也许还有另一种方法可以实现这两点。 My idea was to get the "Settings"-element and change its layout programmatically, but so far I didn't find a way to get that working. 我的想法是获取“设置”元素并以编程方式更改其布局,但到目前为止,我还没有找到一种方法来实现这一点。 Or do I really have to build the footer myself? 或者我真的必须自己构建页脚?

Also, I am not quite sure what buzzwords I should be googling. 另外,我不太确定我应该用Google搜索什么流行语。 Maybe there is already an easy answer out there. 也许已经有一个简单的答案了。

My current code. 我目前的代码。 Right now there are no layout changes inside the Activity, therefore I did not add it. 现在Activity内部没有布局更改,因此我没有添加它。

activity_main.xml: activity_main.xml中:

<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/main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".main.MainActivity">

    <!-- The content -->
    <LinearLayout>...</LinearLayout>

    <!-- The navigation drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/main_navigationview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:headerLayout="@layout/mainnav_header"
        app:itemBackground="@drawable/menu_background"
        app:itemIconTint="@color/menu_text"
        app:itemTextColor="@color/menu_text"
        app:menu="@menu/maindrawer">

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

</android.support.v4.widget.DrawerLayout>

menu.xml: menu.xml文件:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<group android:id="@+id/main_drawer_menu1" android:checkableBehavior="single">
    <item
        android:id="@+id/main_navigationview_request"
        android:checkable="false"
        android:enabled="false"
        android:icon="@drawable/ic_navigationdrawer_request"
        android:title="@string/main_navigation_request"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_invitations"
        android:checked="true"
        android:icon="@drawable/ic_navigationdrawer_invitations"
        android:title="@string/main_navigation_invitations"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_prev"
        android:icon="@drawable/ic_navigationdrawer_previous"
        android:title="@string/main_navigation_previnvites"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_info"
        android:icon="@drawable/ic_navigationdrawer_info"
        android:title="@string/main_navigation_info"
        app:actionLayout="@layout/menuitem_default" />
</group>
<group android:id="@+id/main_drawer_menu2" android:checkableBehavior="single">
    <item
        android:id="@+id/main_navigationview_settings"
        android:checked="true"
        android:icon="@drawable/ic_navigationdrawer_settings"
        android:title="@string/main_navigation_settings"
        app:actionLayout="@layout/menuitem_default" />
    <item
        android:id="@+id/main_navigationview_logout"
        android:icon="@drawable/ic_navigationdrawer_logout"
        android:title="@string/main_navigation_logout"

        app:actionLayout="@layout/menuitem_caution" />
</group>

This line remove padding between icon and text. 此行删除图标和文本之间的填充。

only add below line in dimen.xml file 只在dimen.xml文件中添加以下行

<dimen tools:override="true" name="design_navigation_icon_padding">10dp</dimen>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM