作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我不确定这是否是一个常见问题,我在类似问题上找不到任何内容,但也许我只是没有正确命名..
简要说明:
我正在尝试附加到我的抽屉导航,它外面有一个按钮( float 按钮),这样即使抽屉关闭时按钮也可见,所以拖动按钮打开抽屉..
真实应用示例:
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"
(所以按钮将能够越过边界..)
这是它的样子(在预览中):
在实际测试中,按钮确实位于图片中的位置,但如果抽屉完全关闭,按钮就会消失。
如果我稍微打开抽屉,按钮就会变得可见..
无论如何,按钮不响应触摸..我无法通过拖动按钮关闭抽屉..
那么..我该怎么做才能解决这个问题?我什至接近?或者我应该开始诅咒一些触摸听众?
提前致谢!
最佳答案
将按钮放在导航 View 之外
button.setOnClikclistener({
drawer.closeDrawer(GRAVITY) / drawer.openDrawer(GRAVITY)
}
如果您希望 Button 沿着 Drawer 的边缘移动,您可以使用 Coordinator 布局和填充物为 Button 实现单独的行为
这可以派上用场 https://www.bignerdranch.com/blog/customizing-coordinatorlayouts-behavior/
关于android - 如何将抽屉导航关联到外部的拖动按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38285384/
我是一名优秀的程序员,十分优秀!