如何将 floatingactionbutton 放在布局的末尾
How place floatingactionbutton on end of layout
我想将我的浮动操作按钮放在相对布局底部的末端。我如何做到最好和最实用?
这是一张截图,它应该是这样的:
如果你的父布局是相对布局。
只需使用
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>
此功能仅在您的父布局是协调器时有效 layout.This 可以使用 app:layout_anchor=""
和 app:layout_anchorGravity=""
实现
像这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
希望这对您有所帮助。
我想将我的浮动操作按钮放在相对布局底部的末端。我如何做到最好和最实用?
这是一张截图,它应该是这样的:
如果你的父布局是相对布局。 只需使用
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_plus_sign"
app:elevation="4dp"
/>
</RelativeLayout>
此功能仅在您的父布局是协调器时有效 layout.This 可以使用 app:layout_anchor=""
和 app:layout_anchorGravity=""
像这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.myapp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/appBar"
>
<!-- Put your content that is supposed to be in the appbar here -->
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/your_drawable_resource_file"
app:borderWidth="0dp"
app:fabSize="normal"
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="left|bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
希望这对您有所帮助。