活动中未显示底部导航栏

时间:2018-08-09 21:30:14

标签: java android android-actionbar navigationbar

我有一个标题为标题的活动,一个带有全纸牌的recyclerview片段和一个底部导航栏。

我无法同时显示全部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>

但这给出了以下输出:

enter image description here

这是该片段的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>

1 个答案:

答案 0 :(得分:0)

这是您的布局,已简化:

<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根本没有空间,因此您将看不到其中的任何内容。

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

<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,并将weight属性添加到CoordinatorLayout。

相关问题