【问题标题】:Bottom Navigation Bar not shown in activity活动中未显示底部导航栏
【发布时间】:2018-08-09 21:30:13
【问题描述】:

我有一个带有标题的活动,一个带有满是卡片的回收视图的片段和一个底部导航栏。

我无法毫无问题地同时显示所有 3 个,我最近一次显示所有 3 个,但条形图占用了卡片空间。

现在这是我认为应该可以工作的 XML:

<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
tools:context=".habits.HabitsActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="313dp"
        android:layout_height="166dp"
        android:layout_gravity="center_horizontal"
        app:srcCompat="@drawable/goodreasons" />


<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/contentFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

</android.support.design.widget.CoordinatorLayout>


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom">


<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" />

</FrameLayout>


</LinearLayout>

但这给出了这个输出:

这是片段的 xml,以防您认为它也相关。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:padding="5dp"

>
<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    android:layout_gravity="center"
    />


</LinearLayout>

【问题讨论】:

    标签: java android android-actionbar navigationbar


    【解决方案1】:

    这是你的布局,精简:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <ImageView
            android:layout_width="313dp"
            android:layout_height="166dp"/>
    
        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    </LinearLayout>
    

    您的问题是CoordinatorLayout 的高度为match_parent,因此它将占用ImageView 没有的所有空间。这样FrameLayout 就完全没有空间了,所以你将看不到里面的任何东西。

    最好的办法可能是在CoordinatorLayout 上使用layout_weight 以使其尽可能多地占用空间同时仍为其他视图留出空间。像这样:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <ImageView
            android:layout_width="313dp"
            android:layout_height="166dp"/>
    
        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>
    

    我所做的唯一更改是将 CoordinatorLayout 的高度设置为 0dp,将 FrameLayout 的高度设置为 wrap_content,并将权重属性添加到 CoordinatorLayout。

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多