android - FloatingActionButton 在 ViewPager 中不可见
问题描述
我有一个 ViewPager,里面有一个在屏幕上不可见的 FloatingActionButton。在 ActivityMain 文件中,我没有采取任何行动。这是我的 xml 文件:
<?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=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@android:drawable/arrow_up_float"
android:focusable="true"
app:layout_anchor="@id/viewpager"/>
</androidx.viewpager.widget.ViewPager>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
移动你的FloatingActionButton
外部ViewPager
试试这个方法
<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=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
</androidx.viewpager.widget.ViewPager>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="@android:drawable/arrow_up_float"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- c# - 获取 DataTable 列中某个值的出现次数
- javascript - TypeError:无法读取 sweetAlert 中未定义的属性“setState”
- typescript - 打字稿冗余条件
- c# - 表单大小和比例错误
- android - 调用 onAddStream() 时不加载远程视频
- c++ - 在 C++ 中查找立方根的算法
- azure-devops - Azure DevOps 多仓库管道
- python - 如何使用 r 或 python 在 google sheet 中编写公式?
- security - 如何禁用对 3DES 密码套件的 TLS/SSL 支持?
- pyspark - 在 python 代码中添加 spark 命令的位置