在过去的一个小时里,我一直在搜索这里和其他网站,试图找出我做错了什么。正如标题所示,我需要一个带按钮的页眉、一个滚动视图,然后是一个带按钮的页脚。我希望页眉和页脚始终可见。找到的所有内容都表示要创建一个相对布局,将其与父顶部对齐,创建页脚,将其与父底部对齐,然后创建一个滚动视图,将其设置在页脚上方和标题下方。由于某种原因,我的代码决定忽略这一点。
<RelativeLayout
android:id="@+id/topBar_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/colorBackground">
<Button
android:id="@+id/charInfoBtn_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="General"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</RelativeLayout>
<ScrollView
android:id="@+id/genLayoutScroll_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottomBar_id"
android:layout_below="@id/topBar_id>
<LinearLayout
//bunch of junk that users scroll through
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/bottomBar_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/colorBackground">
<Button
android:id="@+id/genApplyBtn_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
使用它作为我当前的代码,滚动视图位于顶部栏和底部栏的顶部。
如果我删除layout_above和layout_below行,并将其替换为app:layout_constraintBottom_toTopOf =“@id/bottomBar_id”,那么滚动视图不再越过我的底部栏,但现在顶部栏和滚动视图的顶部丢失了。
然后我将 app:layout_constraintTop_toBottomOf="@id/topBar_id" 添加到滚动视图,它会返回到与具有layout_below 和layout_above 相同的状态。
我确信我在这里错过了一些东西,我只是不知道我错过了什么。希望有人能指出我犯的愚蠢错误。
PS我知道我的一些代码现在有点草率,主要是因为试图解决这个问题。