问题描述
我有一个非常简单的活动,有一个抽屉和两个线性布局。 我需要实现:如果我们在按钮布局的任何位置水平向右滑动,它将打开抽屉(与 Telegram 应用程序中的相同)。但它不应该在顶部布局上打开它,因为它包含一个寻呼机。
你能帮我实现它吗?
解决方法
将抽屉布局设为父布局。将您的视图放在抽屉布局中。
<!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
//Your view here
</androidx.drawerlayout.widget.DrawerLayout >