底部软NavigationBar与我的ListView重叠

问题描述 投票:14回答:4

我在Nexus 5(Android 5)上运行了我的应用程序,但是我遇到了底部的软NavigationBar与ListView的最后一项重叠的问题。我试图将fitsSystemWindows添加到我的样式和ListView但是没有用。

我的布局的XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@color/sf4l"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ListView android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/sf4l" />
</LinearLayout>
android listview android-listview navigationbar
4个回答
43
投票

将其添加到values-v21目录中的themes.xml:

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

示例(我正在使用AppCompat for actionbars):

<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="homeAsUpIndicator">@drawable/new_indicator</item>
    <item name="android:homeAsUpIndicator">@drawable/new_indicator</item>
    <item name="actionModeBackground">@android:color/black</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>

2
投票

这是因为listView的高度等于全屏高度,但是操作栏将布局推低几个像素,导致布局重叠导航按钮。

如果您在操作栏下有全屏碎片容器,也会发生这种情况。

修复此问题是测量屏幕高度和操作栏,然后将父视图的高度设置为差异。例:

@Override
public void onWindowFocusChanged (boolean hasFocus) {
    LinearLayout lMain = (LinearLayout) findViewById(R.id.lMain);
    lMain.getLayoutParams().height = lMain.getHeight() - getNavigationBarHeight();
}
  • 在绘制/渲染布局后,您必须执行此操作。在onCreate或onResume上为时尚早。在onWindowFocusChanged()中这样做可能是愚蠢的矫枉过正,但它确实有效。

2
投票

我在这篇文章中尝试了接受的答案,就像许多它对我不起作用。

但是以下工作人员对我来说。

  <item name="android:windowTranslucentNavigation">false</item>

我放置样式-21.xml

它的作用是使软导航栏具有坚实的背景,并且现在可以正确地呈现组件。


0
投票

很容易解决。只需使用ConstraintLayout。将顶视图的下边缘与底视图的上边缘对齐。

样品如下: -

XML: -

    <android.support.constraint.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ListView
    android:id="@+id/list_item"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:divider="@color/black"
    android:dividerHeight="2dp"
    app:layout_constraintBottom_toTopOf="@+id/navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0"
    app:layout_constraintHorizontal_bias="1.0"></ListView>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />
    </android.support.constraint.ConstraintLayout>

输出设计: -

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.