d1277281973 2023-03-23 11:14 采纳率: 60%
浏览 17
已结题

Android DrawerLayout 问题

如题,我想实现滑动菜单功能
这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

        <Button
            android:id="@+id/learnNew"
            android:layout_width="133dp"
            android:layout_height="63dp"
            android:layout_marginStart="64dp"
            android:layout_marginTop="232dp"
            android:text="学习"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/userWelcome"
            android:layout_width="173dp"
            android:layout_height="52dp"
            android:layout_marginStart="52dp"
            android:layout_marginTop="96dp"
            android:text="TextView"
            android:textSize="34sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="start"
        android:background="#FFF"
        android:text="This is menu"
        android:textSize="30sp"
        />
</androidx.drawerlayout.widget.DrawerLayout>

但是显示出来的却是这个样子:

img

划也划不动,不过还能点击到被遮盖的按钮,这是怎么回事?

  • 写回答

2条回答 默认 最新

  • 程序yang 全栈领域优质创作者 2023-03-23 11:42
    关注

    将侧滑菜单的内容放在一个布局中试试看:

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <!-- 在这里放置你的主界面布局 -->
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    
        <!-- 侧滑菜单布局 -->
        <LinearLayout
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            android:orientation="vertical">
    
            <!-- 在这里放置你的侧滑菜单布局 -->
    
        </LinearLayout>
    
    </androidx.drawerlayout.widget.DrawerLayout>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月31日
  • 已采纳回答 3月23日
  • 创建了问题 3月23日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来