android– 两个浮动动作按钮彼此相邻

android– 两个浮动动作按钮彼此相邻,第1张

概述材料设计文档中有一个Google地图示例,其中显示了两个彼此相邻浮动 *** 作按钮(实际上,一个在另一个之上).这是怎么做到的?我在协调器布局中有两个FAB,但它们最终相互叠加,因此您只能看到一个按钮.<?xmlversion="1.0"encoding="utf-8"?><android.support.design.widget.Coordina

材料设计文档中有一个Google地图示例,其中显示了两个彼此相邻的浮动 *** 作按钮(实际上,一个在另一个之上).

这是怎么做到的?我在协调器布局中有两个FAB,但它们最终相互叠加,因此您只能看到一个按钮.

<?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-auto"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <!-- Use themeOverlay to make the toolbar and tablayout text             white -->    <androID.support.design.Widget.AppbarLayout        androID:ID="@+ID/abl_top"        androID:layout_height="wrap_content"        androID:layout_wIDth="match_parent"        androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">        <androID.support.v7.Widget.Toolbar            androID:ID="@+ID/toolbar"            androID:fitsSystemwindows="true"            androID:layout_wIDth="match_parent"            androID:layout_height="?attr/actionbarSize"            app:popuptheme="@style/themeOverlay.AppCompat.Dark.Actionbar"/>    </androID.support.design.Widget.AppbarLayout>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:orIEntation="vertical">        <ImageVIEw            androID:ID="@+ID/img_photo"            androID:layout_wIDth="match_parent"            androID:layout_height="256dp"            androID:background="#C5C5C5"/>        <EditText            androID:ID="@+ID/text_name"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_below="@ID/img_baby"            androID:layout_alignParentStart="true"            androID:layout_alignParentleft="true"            androID:hint="name"            androID:drawableleft="@drawable/ic_account"            androID:drawablepadding="20dp"            androID:textAppearance="?androID:attr/textAppearanceSmall" />        <TextVIEw            androID:ID="@+ID/text_dob"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_below="@ID/text_name"            androID:layout_alignParentStart="true"            androID:layout_alignParentleft="true"            androID:hint="Date of birth"            androID:drawableleft="@drawable/ic_cake"            androID:drawablepadding="20dp"            />    </linearLayout>    <androID.support.design.Widget.floatingActionbutton        androID:ID="@+ID/fab_camera"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margin="16dp"        androID:src="@drawable/ic_camera"        androID:clickable="true"        app:fabSize="mini"        app:layout_anchor="@ID/img_photo"        app:layout_anchorGravity="bottom|right|end"/>    <androID.support.design.Widget.floatingActionbutton        androID:ID="@+ID/fab_gallery"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margin="16dp"        androID:src="@drawable/ic_image"        androID:clickable="true"        app:fabSize="mini"        app:layout_anchor="@ID/img_photo"        app:layout_anchorGravity="bottom|right|end"/></androID.support.design.Widget.CoordinatorLayout>

解决方法:

它是布局重力和锚重力的组合,并且可以使用它(锚定项目的边缘)来使其工作,看看我成功使用的xml:

<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_margin="@dimen/fab_margin"    androID:src="@androID:drawable/ic_dialog_info" /><androID.support.design.Widget.floatingActionbutton    androID:ID="@+ID/fab2"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_gravity="top|end"    androID:layout_marginBottom="0dp"    androID:layout_marginEnd="0dp"    androID:layout_marginleft="0dp"    androID:layout_marginRight="0dp"    androID:layout_marginStart="0dp"    androID:layout_margintop="0dp"    androID:src="@androID:drawable/ic_media_play"    app:layout_anchor="@ID/fab"    app:layout_anchorGravity="top" />
总结

以上是内存溢出为你收集整理的android – 两个浮动动作按钮彼此相邻全部内容,希望文章能够帮你解决android – 两个浮动动作按钮彼此相邻所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存