【发布时间】:2016-07-09 19:09:06
【问题描述】:
我不确定这是否是常见问题,我找不到类似的东西,但也许我只是没有正确命名它..
简要说明:
我正在尝试将一个按钮(浮动按钮)附加到我的导航抽屉,因此即使抽屉关闭,该按钮也可见,因此拖动按钮会打开抽屉..
真实应用示例:
像 Waze 这样的一些应用程序有:
我的尝试..
所以在我发疯并设置触摸监听器和烦人的东西之前,我先尝试简单化.. 我尝试简单地在 xml 文件的 NavigationView 中添加按钮..
这是我的 acivity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="-80dp"
android:text="drag me->" />
</android.support.design.widget.NavigationView>
我还确保将此行添加到父级:
android:clipChildren="false"
(这样按钮就可以越界了..)
这是它的样子(在预览中):
在实际测试中,按钮确实在图片中的位置,但如果抽屉完全关闭,按钮就会消失..
如果我稍微打开抽屉,按钮就会变得可见..
无论如何,按钮对触摸没有反应..我无法通过拖动按钮来关闭抽屉..
所以.. 我能做些什么来解决这个问题?我什至接近吗?或者我应该开始诅咒一些触摸听众?
先谢谢了!
【问题讨论】:
-
你实现了这个。我正在寻找相同的实现?