如何在android中为抽屉布局添加paddingBottom?

问题描述 投票:0回答:1

我正在做一个使用抽屉布局的android项目。抽屉布局包含了许多项目,因此是可以滚动的,问题是,我需要最后一个项目有一个paddingBottom。问题是,我需要最后一个项目有一个padding bottom,这样在滚动到最后一个项目后会有一些间距。

enter image description here

从上面的截图来看,我怎样才能在最后一个项目 "登出 "和屏幕结束之间添加一些padding。

我已经尝试在抽屉布局中添加填充底部,但仍然没有效果。

 <androidx.drawerlayout.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_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start"
        android:paddingBottom="@dimen/_120sdp"
        android:clipToPadding="false">

我也试过将导航视图包围在滚动视图中,但也不行。

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:paddingBottom="@dimen/_120sdp">

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</ScrollView>

这是我在抽屉布局中的最后一个元素。

<item
        android:paddingBottom="@dimen/_190sdp"
        android:title="@string/action">
        <menu>
            <item
                android:id="@+id/nav_rate_us"
                android:title="@string/rate_us" />
            <item
                android:id="@+id/nav_log_out"
                android:paddingBottom="@dimen/_120sdp"
                android:title="@string/log_out" />

        </menu>
    </item>

如何实现这个功能?

android android-studio android-layout navigation-drawer drawerlayout
1个回答
1
投票

在你的菜单资源文件的最后添加一个虚项。

 <item
    android:title=""
    android:enabled="false" >
</item>
© www.soinside.com 2019 - 2024. All rights reserved.