我正在对浮动的动作按钮做一些操作。我有一个列表视图,并在我的屏幕底部显示google广告,浮动的操作按钮显示在相同的位置(底部|结束)。所以动作按钮隐藏了广告。
我想要移动浮动的行动按钮略高于广告线性布局。
请看图片:

我的代码如下:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|end"
android:src="@drawable/fav"
android:adjustViewBounds="false" />
adLayoutId is ad layout id请帮帮忙。
提前谢谢。
发布于 2017-07-11 03:54:58
您应该使用RelativeLayout,正如我们所知,在RelativeLayout中较晚的子代往往会浮动在RelativeLayout中较早的子代之上。
因此,要让FAB浮动在任何布局上,请确保在所有视图之后定义FAB (在XML布局的末尾)。
如果使用android:layout_margin="@dimen/fab_margin",操作FAB的最佳方法是设置视图之间的依赖关系,例如:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/adLayoutId"/>
<LinearLayout
android:id="@+id/adLayoutId"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@android:color/black"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/adLayoutId"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/fav"/>
</RelativeLayout>浮动动作按钮将始终位于广告线性布局之上,并且独立于广告布局大小。希望能有所帮助。
发布于 2017-07-11 03:24:16
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="100dp"
android:layout_marginRight="30dp"
/>发布于 2020-11-17 22:09:09
fab按钮中的这两行代码帮助我解决了这个问题:
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"下面是我单独使用的按钮的完整代码:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_newStudent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:contentDescription="@string/todo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_baseline_add_24" />https://stackoverflow.com/questions/45019871
复制相似问题