sir*_*r77 3 xml android android-layout navigation-drawer
大家好我想改变我的导航抽屉物品的高度,我不知道怎么样,我到处寻找并尽我所能,但似乎没有任何作用..
这是我的导航抽屉项目,它被定制为在该图像下有文本,但我也希望该图像更大一些.
我期待的结果是:
每个项目的高度约为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>
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
最后菜单; 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>
Run Code Online (Sandbox Code Playgroud)
任何想法如何实现我想要的?提前致谢
编辑:当我在我的自定义项目中放大图像时,如下所示:
这是在menu_item.xml中
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/menu_icon"/>
Run Code Online (Sandbox Code Playgroud)
..我得到这个结果:
如您所见,我的图像比项目大..
Mou*_*esh 19
将其添加到styles.xml中
<style name="NavigationTheme" parent="AppTheme">
<item name="listPreferredItemHeightSmall">60dp</item><!-- menu item height- vary as u need -->
</style>
Run Code Online (Sandbox Code Playgroud)
并且您在抽屉布局中的导航视图shd包含该主题
<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" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9042 次 |
| 最近记录: |