我在FrameLayout
中放置了ConstraintLayout
,但我认为它受到了适当的限制。但是在应用程序中,它的位置不正确。 FrameLayout
在运行时被适当的片段替换。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.chapters.ChapterActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_chapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Chapters"
app:titleTextColor="@color/White" />
<FrameLayout
android:id="@+id/chapter_fragment_container_frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="500dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.388"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_chapter"
app:layout_constraintVertical_bias="1.0" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:itemIconTint="@color/White"
app:itemTextColor="@color/Wheat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/chapter_bottom_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</androidx.constraintlayout.widget.ConstraintLayout>
这是IDE中显示的内容:
但是这是我在设备中得到的:
[FrameLayout
应该放置在工具栏和底部导航栏之间,应该由LinearLayout/Relative
一个完成,虽然还没有尝试..但是这有什么问题。
如下更改此FrameLayout部分:
<FrameLayout
android:id="@+id/chapter_fragment_container_frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:minHeight="500dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.388"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_chapter"
app:layout_constraintVertical_bias="1.0" />
之所以发生,是因为match_constraint
。如果为top, bottom, start, and end
定义了约束,则应该为0dp
和height
定义width
来查看。
将framelayout的android:layout_height属性从“ match_parent”更改为“ wrap_content”
将FrameLayout的高度更改为0dp,
<FrameLayout
android:id="@+id/chapter_fragment_container_frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:minHeight="500dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.388"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_chapter"
app:layout_constraintVertical_bias="1.0" />