我有一個AppCompatActivity與下面EmptyView的ListView的隱藏BottomNavigationView
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/user_title"
android:background="@drawable/user_title_color"
android:textColor="@android:color/white"
android:textAppearance="@android:style/TextAppearance.Large"/>
<ListView android:id="@+id/joggings_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"/>
<LinearLayout
android:id="@+id/empty_list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center">
<TextView
android:text="No joggings yet"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/empty_add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_jogging"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentRight="true"
android:layout_gravity="end|bottom"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:src="@drawable/ic_plus"
app:borderWidth="0dp" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimaryDark"
android:foregroundTint="@color/colorAccent"
app:itemTextColor="@color/bottom_navigation_color"
app:itemIconTint="@color/bottom_navigation_color"
app:menu="@menu/bottom_navigation_main" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
和在我的代碼我有佈局的列表視圖 mListView.setEmptyView(findViewById(R.id.empty_list));
爲了顯示消息和列表爲空時的「添加」按鈕。我的問題是,當列表爲空時,BottomNavigationView被隱藏,用戶無法導航到其他活動。
我能想到的一個可能的解決方案是在空白布局中添加另一個BottomNavigationView,但它看起來很醜。
任何其他解決方案?
似乎是一個佈局順序問題,你的BottomNavigationView從屏幕上被拉斷,所以一個可能的解決方案是使用一個相對佈局作爲協調員的直接兄弟姐妹,確保所有觀點都適合屏幕。 –