【发布时间】:2018-06-06 01:31:29
【问题描述】:
我想在NavigationView 中增加single MenuItem 的高度。
我正在尝试将 Google MapFragment 放入项目的 actionLayout 中,如下所示,但我希望地图的高度更大。
有什么想法吗?
注意:
- 我想利用 NavigationView 的标准菜单布局(我不希望像使用 this answer 那样实现整个自定义菜单布局)。
- 我不想更改所有项(如this answer)的高度,只更改地图项。
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
...
<item
android:id="@+id/nav_map"
app:showAsAction="always"
android:title="@string/nav_map"
app:actionLayout="@layout/fragment_map" />
...
</menu>
fragment_map.xml
这里调整android:layout_height没有效果。
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/nav_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:mapType="normal"
map:liteMode="true"/>
在Activity.onCreate(...) 在MainActivity.kt
在动作视图上设置高度在这里没有效果。
val mapItem = nav.menu.findItem(R.id.nav_map)
// Has no effect: trying to set height to 128dp
mapItem.actionView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 128)
// Hack: hide title
mapItem.title = null
val mapView = supportFragmentManager.findFragmentById(R.id.nav_map_fragment) as SupportMapFragment
mapView.getMapAsync { map ->
...
}
【问题讨论】:
-
找到解决办法了吗
标签: android android-layout navigationview android-navigationview