Yar*_*hen 6 android navigation-drawer
我不确定这是否是常见的问题,我找不到类似的东西,但也许我只是没有说出正确的名称..
简要说明:
我正试图将我的导航抽屉,一个按钮(浮动按钮)连接到它外面,这样即使抽屉关闭也可以看到按钮,因此拖动按钮会打开抽屉..
真实应用示例:
像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>
Run Code Online (Sandbox Code Playgroud)
我还确保将此行添加到父级:
android:clipChildren="false"
Run Code Online (Sandbox Code Playgroud)
(这样按钮就可以越过边界......)
这就是它的样子(在预览中):
在实际测试中,按钮确实位于图片中的位置,但如果抽屉完全关闭,则按钮消失.
如果我打开抽屉一点点按钮就会变得可见..
无论如何,按钮不响应触摸..我无法通过拖动按钮关闭抽屉..
那么..我该怎么做才能解决这个问题?我甚至关闭了吗?或者我应该开始诅咒一些触摸听众?
谢谢!
将按钮放在导航视图之外
button.setOnClikclistener({
drawer.closeDrawer(GRAVITY) / drawer.openDrawer(GRAVITY)
}
Run Code Online (Sandbox Code Playgroud)
如果您希望 Button 沿着 Drawer 的边缘移动,您可以使用 Coordinator 布局和内容为 Button 实现单独的行为
这可以派上用场https://www.bignerdranch.com/blog/customizing-coordinatorlayouts-behavior/
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |