android - 为什么我的浮动操作按钮在应用启动时会跳到页面顶部?
问题描述
目前,我的 android 应用程序中的回收站视图和浮动操作按钮存在问题。当我启动应用程序时,按钮总是跳到页面的右上方。
RecyclerView 和 Button 位于片段内。目前我正在使用 ConstraintLayout 来表示 Button 应该始终出现在屏幕的右端。但是,我也尝试使用具有锚点和重力属性的 RelativeLayout 和 CoordinatorLayout。在 Android Studio 中,布局显示正确,按钮位于屏幕右下方。当我在手机上启动应用程序时,它就会出现在屏幕的右上角...
布局预览:
当我在手机上启动应用程序时:
这是我现在用于片段的代码:
<?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"
android:id="@+id/fragment_bucketlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/colorPrimary">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_bucketList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_addToBucketList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
提前感谢您的帮助!
解决方案
我使用RelativeLayout 解决了这个问题。存在浮动操作按钮始终显示在底部边缘并“卡在”底部导航栏(华为设备)的问题。属性 app:useCompatPadding="true" 解决了这个问题。
这是更新的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_bucketlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@color/colorPrimary">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_bucketList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_addToBucketList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_edit"
app:useCompatPadding="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
推荐阅读
- html - 发生数据库更改时刷新 Angular 中的下拉菜单
- sql - 在 ORACLE SQL 中将一组列转换为行
- flutter - Flutter 小部件的便携式/二进制格式?
- reactjs - 如何根据本地存储重新渲染反应组件?
- rust - 如何抑制源自宏的 Clippy 警告?
- html - Flex box 根据屏幕分辨率对特定项目进行分组
- protractor - 如何使用 webdriver manager 设置 chome 二进制位置
- linux - 如何在shell脚本中用逗号替换变量中的换行符
- html - Angular 9 - 不能用css变量改变身体背景
- python - Pandas 将一行的值拆分为两个不同的行