gpt4 book ai didi

android - 如何自定义抽屉导航项目高度

转载 作者:行者123 更新时间:2023-12-02 10:05:57 24 4
gpt4 key购买 nike

大家好,我正在尝试更改抽屉导航项目的高度,但我不知道如何操作,我到处寻找并尽了最大努力,但似乎没有任何效果。

Result

这是我的抽屉导航项目,它被定制为在该图像下有一个文本,但我也希望该图像更大一点。

我期待的结果是这样的:

Menu Items

每个项目的高度约为 75dp,而且我希望菜单的宽度较短,以便在该图像中呈现出这种外观。

当然,我正在为我的项目使用自定义布局,我将其命名为:menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="10dp">

<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/menu_icon"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu Title"
android:textSize="16sp"
android:textColor="@color/white" />

</LinearLayout>

我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

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

最后是菜单; activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >

<item
android:id="@+id/nav_profile"
app:actionLayout="@layout/menu_item"/>
</menu>

有什么想法可以实现我想要的吗?提前致谢

编辑:当我放大自定义项目中的图像时,如下所示:

这位于menu_item.xml

<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/menu_icon"/>

..我得到这个结果:

result2

如您所见,我的图片比商品大..

最佳答案

将其添加到您的 styles.xml

<style name="NavigationTheme" parent="AppTheme">
<item name="listPreferredItemHeightSmall">60dp</item><!-- menu item height- vary as u need -->
</style>

抽屉布局中的导航 View 包含像这样的主题

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:theme="@style/NavigationTheme"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />

关于android - 如何自定义抽屉导航项目高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44644588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com