为什么将FrameLayout与BottomNavigation一起使用?

时间:2019-07-08 12:26:43

标签: android android-fragments bottomnavigationview

在许多示例中,我看到这样的内容:

<?xml version="1.0" encoding="utf-8"?>
<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="net.simplifiedcoding.bottomnavigationexample.MainActivity">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="56dp"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/colorNavIcon"
        app:itemTextColor="@color/colorNavText"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

为什么这里有FrameLayout?毕竟,如果将其删除,那么bottomNavigation将始终保留在原位,并且片段将占据上方区域。那么为什么要在几乎所有地方都添加FrameLayout?谢谢

2 个答案:

答案 0 :(得分:0)

为什么在这里使用FrameLayout?

FrameLayout在这里用于提供内容。通常,FrameLayout可以完成其他布局的工作,并且可以与Fragments一起很好地工作,这就是为什么FrameLayout经常使用的原因,但是您可以在此处使用任何其他布局。

答案 1 :(得分:0)

private void RandomiseLines()
{
    var rnd = new Random();

    Values = new ObservableCollection<double>();

    for (int i = 0; i < 3; i++)
    {
        Values.Add(rnd.Next(1, 300));
    }
}

用于将内容(视图)作为片段添加。