我怎么可以添加新的"浮动操作按钮"两个小部件/布局之间 [英] How can I add the new "Floating Action Button" between two widgets/layouts
问题描述
我想你已经看到了新的Android的设计准则,以新的浮动动作按钮又名FAB
I guess you have seen the new Android design guidelines, with the new "Floating Action Button" a.k.a "FAB"
例如,这粉红色的按钮:
For instance this pink button:
我的问题听起来很愚蠢,我已经尝试了很多东西,但什么是把这个按钮在两种布局的交集?
My question sounds stupid, and I have already tried a lot of things, but what is the best way to put this button at the intersection of two layouts?
在上述为例,该按钮被完全有条件我们可以想像是一个ImageView的和RelativeLayout的之间。
In the above exemple, this button is perfectly placed between what we can imagine to be an ImageView and a relativeLayout.
我已经尝试了很多的调整,但我相信有一个适当的方式做到这一点。
I have already tried a lot of tweaks, but I am convinced there is a proper way to do it.
推荐答案
最佳实践:
- 添加
编译com.android.support:design:22.2.0
来摇篮文件 - 使用
CoordinatorLayout
作为根查看。 - 添加
layout_anchor
的FAB并将其设置为俯视图 - 添加
layout_anchorGravity
的FAB,并将其设置为:底部|右|结束
- Add
compile 'com.android.support:design:22.2.0'
to gradle file - Use
CoordinatorLayout
as root view. - Add
layout_anchor
to the FAB and set it to the top view - Add
layout_anchorGravity
to the FAB and set it to:bottom|right|end
<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">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@android:color/holo_purple"
android:orientation="horizontal"/>
<LinearLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="@android:color/holo_orange_light"
android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_done"
app:layout_anchor="@id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
这篇关于我怎么可以添加新的&QUOT;浮动操作按钮&QUOT;两个小部件/布局之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!