【问题标题】:Android XML FrameLayout and BottomNavigationViewAndroid XML FrameLayout 和 BottomNavigationView
【发布时间】:2018-01-30 14:31:18
【问题描述】:

如何使 FrameLayout 以 BottomNavigationView 的开头结束? FrameLayout 的内容被导航视图覆盖。

这是xml:

<?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="...">

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

</FrameLayout>

<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>

【问题讨论】:

    标签: android xml android-framelayout bottomnavigationview


    【解决方案1】:

    如果你想继续使用constraintlayout,你可以在xml的framelayout中添加以下属性:

    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    

    【讨论】:

    • @Mantas Laurinavičius 是对的。不要忘记将layout_height 设置为 0dp
    【解决方案2】:

    这个对我有用。 (灵感来自 jackycflau)

    <?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="eu.ibsdevelopment.auto.mvp.view.main.MainActivity">
    
    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@+id/navigation"
        app:layout_constraintBottom_toTopOf="@+id/navigation"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="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: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>
    

    【讨论】:

      【解决方案3】:

      试试这个:

      <RelativeLayout
          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">
      
           <FrameLayout
              android:layout_above="@+id/navigation"
              android:id="@+id/content"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              tools:layout_editor_absoluteY="8dp"
              tools:layout_editor_absoluteX="8dp" />
      
      
          <android.support.design.widget.BottomNavigationView            
              android:id="@+id/navigation"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="?android:attr/windowBackground"
              android:layout_alignParentBottom="true"
              app:menu="@menu/action_admin_bottom_menu" />
      
      </RelativeLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-15
        • 1970-01-01
        相关资源
        最近更新 更多