[英]Bottom Navigation Bar not shown in activity
I have an activity with a title, a fragment with a recyclerview full of cards and a bottom navigaton bar. 我有一个带有标题的活动,一个带有全纸牌的recyclerview的片段和一个底部的导航栏。
I cannot manage to show all 3 together without problems, the closest I have been is showing all 3, but with the bar taking space from the cards space. 我无法毫无问题地同时显示全部3个,最近的一次我显示了全部3个,但是条形图占用了纸牌空间。
Right now this is the XML which I thought should be working: 现在,这是我认为应该可以使用的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>
But this gives this output: 但这给出了以下输出:
This is the xml of the fragment, in case you think it is relevant too. 这是该片段的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>
Here's your layout, stripped down: 这是您的布局,已简化:
<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>
Your problem is that the CoordinatorLayout
has a match_parent
height, so it will take up all of the space that the ImageView
doesn't. 您的问题是
CoordinatorLayout
的高度为match_parent
,因此它将占用ImageView
没有的所有空间。 That leaves no space at all for the FrameLayout
, so you won't be able to see anything inside of it. 这样就不会为
FrameLayout
留下任何空间,因此您将看不到其中的任何内容。
Probably the best thing to do would be to use layout_weight
on the CoordinatorLayout
to make it take up as much space as it can while still leaving room for other views. 可能最好的办法是在
CoordinatorLayout
上使用layout_weight
使其占用尽可能多的空间, 同时仍然为其他视图留出空间。 That would look something like this: 看起来像这样:
<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>
The only changes I made were to set the CoordinatorLayout's height to 0dp
and the FrameLayout's height to wrap_content
, and to add the weight attribute to the CoordinatorLayout. 我所做的唯一更改是将CoordinatorLayout的高度设置为
0dp
,将FrameLayout的高度设置为wrap_content
,并将weight属性添加到CoordinatorLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.