【发布时间】:2017-06-20 05:35:19
【问题描述】:
大家好,我正在尝试更改导航抽屉项目的高度,但我不知道怎么做,我到处寻找并尽了最大努力,但似乎没有任何效果..
这是我的导航抽屉项目,它被定制为在该图像下有一个文本,但我希望该图像更大一点。
我期待的结果是这样的:
每个项目的高度约为 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"/>
..我得到这个结果:
如你所见,我的图片比商品大..
【问题讨论】:
-
您可以自定义导航布局
-
要实现这一点,只需创建一个自定义布局。
-
@Anas 你试过我的答案吗...??
标签: android xml android-layout navigation-drawer