如何添加新的“浮动操作按钮"?在两个小部件/布局之间 [英] 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"
例如这个粉色按钮:
我的问题听起来很愚蠢,我已经尝试了很多东西,但是将这个按钮放在两个布局的交叉处的最佳方法是什么?
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.
推荐答案
最佳实践:
- 添加
compile 'com.android.support:design:25.0.1'
到gradle文件 - 使用
CoordinatorLayout
作为根视图. - 将
layout_anchor
添加到FAB并将其设置为顶视图 - 将
layout_anchorGravity
添加到 FAB 并将其设置为:bottom|right|end
- Add
compile 'com.android.support:design:25.0.1'
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>
这篇关于如何添加新的“浮动操作按钮"?在两个小部件/布局之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文