0
我有NavigationView一個DrawerLayout如下所示在充氣導航下面頭視圖自定義視圖中查看機器人
<?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"
tools:openDrawer="start">
<include
layout="@layout/app_bar_dynamic_screen"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<include layout="@layout/navigation_drawer_content"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
在NavigationView,報頭視圖是動態膨脹,如下所示。
View headerView = getCustomHeaderView(navigationView);
if (headerView != null) {
navigationView.addHeaderView(headerView);
}
另一種佈局包含在包含ExpandableListView的NavigationView中。我需要將此佈局放置在膨脹的headerView下面。我通過動態獲取headerView的高度並將「marginTop」屬性設置爲包含的佈局來實現此目的。但是,如果headerView沒有靜態高度(如果wrap_content),則失敗(兩個視圖重疊)。 如何以有效的方式在NavigationView的headerView下方設置包含的佈局。請幫忙。
的[默認抽屜式導航欄查看到ExpandableListView(https://stackoverflow.com/questions/38765790/default-navigation-drawer-view-to-expandablelistview) – random
感謝您的鏈接可能的複製。那就是我所做的。但我的要求是動態獲取高度wrap_content的佈局的標題視圖高度。我使用onWindowFocusChanged方法實現了這一點 –