0

屏幕图像

我不知道为什么我的抽屉布局上有一个问号,也不知道为什么它不起作用,因为我按照 youtube 教程创建了整个屏幕

这是navigation_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/home"
    android:title="Home"/>

<item android:id="@+id/myorders"
    android:title="My Orders"/>
<item android:id="@+id/myplaces"
    android:title="My Places"/>

<item android:id="@+id/mensettings"
    android:title="Settings"/>

</menu>

这是 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".Settings">


<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start">


    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/setting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="150dp"
            android:layout_marginLeft="150dp"
            android:layout_marginRight="150dp"
            android:layout_marginStart="150dp"
            android:layout_marginTop="35dp"
            android:text="Settings"
            android:textColor="#1682E9"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.076"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/maskforsettings"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/setting"
            app:srcCompat="@drawable/maskforset" />

        <ImageView
            android:id="@+id/imageView29"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView28"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/changepass"
            app:layout_constraintTop_toTopOf="@+id/changepass"
            app:srcCompat="@drawable/right" />

        <ImageView
            android:id="@+id/imageView30"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="4dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView29"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/changelang"
            app:layout_constraintTop_toTopOf="@+id/changelang"
            app:srcCompat="@drawable/right" />

        <ImageView
            android:id="@+id/imageView31"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView30"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/tellfriend"
            app:layout_constraintTop_toTopOf="@+id/tellfriend"
            app:srcCompat="@drawable/right" />

        <TextView
            android:id="@+id/changepass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Change Password"
            android:textColor="#5A5A5A"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="@+id/profiletv"
            app:layout_constraintTop_toBottomOf="@+id/view3" />

        <TextView
            android:id="@+id/changelang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Change Language"
            android:textColor="#5A5A5A"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="@+id/changepass"
            app:layout_constraintTop_toBottomOf="@+id/view6" />

        <TextView
            android:id="@+id/tellfriend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Tell A Friend"
            android:textColor="#5A5A5A"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="@+id/changelang"
            app:layout_constraintTop_toBottomOf="@+id/view7" />

        <ImageView
            android:id="@+id/setbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="2dp"
            android:layout_marginTop="40dp"
            app:layout_constraintEnd_toStartOf="@+id/setting"
            app:layout_constraintHorizontal_bias="0.282"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/setbar" />

        <TextView
            android:id="@+id/about"
            android:layout_width="wrap_content"
            android:layout_height="17dp"
            android:layout_marginLeft="32dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="32dp"
            android:text="About"
            android:textColor="#5A5A5A"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/maskforsettings" />

        <ImageView
            android:id="@+id/imageView24"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="236dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="236dp"
            android:layout_marginTop="1dp"
            app:layout_constraintEnd_toEndOf="@+id/maskforsettings"
            app:layout_constraintStart_toEndOf="@+id/about"
            app:layout_constraintTop_toTopOf="@+id/about"
            app:srcCompat="@drawable/right" />


        <View
            android:id="@+id/view4"
            android:layout_width="283dp"
            android:layout_height="0.01dp"
            android:layout_marginTop="15dp"
            android:background="#CFCFC4"
            android:elevation="1dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView24"
            app:layout_constraintStart_toStartOf="@+id/about"
            app:layout_constraintTop_toBottomOf="@+id/about" />

        <View
            android:id="@+id/view3"
            android:layout_width="283dp"
            android:layout_height="0.01dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:background="#CFCFC4"
            android:elevation="1dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView28"
            app:layout_constraintStart_toStartOf="@+id/profiletv"
            app:layout_constraintTop_toBottomOf="@+id/profiletv" />

        <View
            android:id="@+id/view6"
            android:layout_width="283dp"
            android:layout_height="0.01dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:background="#CFCFC4"
            android:elevation="1dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView29"
            app:layout_constraintStart_toStartOf="@+id/changepass"
            app:layout_constraintTop_toBottomOf="@+id/changepass" />

        <View
            android:id="@+id/view7"
            android:layout_width="283dp"
            android:layout_height="0.01dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:background="#CFCFC4"
            android:elevation="1dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView29"
            app:layout_constraintStart_toStartOf="@+id/changelang"
            app:layout_constraintTop_toBottomOf="@+id/changelang" />

        <TextView
            android:id="@+id/profiletv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Profile"
            android:textColor="#5A5A5A"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="@+id/about"
            app:layout_constraintTop_toTopOf="@+id/view4" />

        <ImageView
            android:id="@+id/imageView28"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="236dp"
            android:layout_marginStart="236dp"
            android:layout_marginTop="1dp"
            app:layout_constraintEnd_toEndOf="@+id/imageView24"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/about"
            app:layout_constraintTop_toTopOf="@+id/profiletv"
            app:srcCompat="@drawable/right" />

        <ImageView
            android:id="@+id/logoutIv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/maskforsettings"
            app:srcCompat="@drawable/rect" />

        <TextView
            android:id="@+id/logouttv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="28dp"
            android:text="Logout"
            android:textColor="#FF2323"
            android:textSize="18sp"
            app:layout_constraintEnd_toEndOf="@+id/logoutIv"
            app:layout_constraintStart_toStartOf="@+id/logoutIv"
            app:layout_constraintTop_toTopOf="@+id/logoutIv" />

        <ImageView
            android:id="@+id/deleteIV"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/logouttv"
            app:srcCompat="@drawable/rect" />

        <TextView
            android:id="@+id/daTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="35dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:text="Delete Account"
            android:textColor="#FF2323"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="@+id/deleteIV"
            app:layout_constraintEnd_toEndOf="@+id/deleteIV"
            app:layout_constraintStart_toStartOf="@+id/deleteIV" />


    </android.support.constraint.ConstraintLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/mynavbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        app:menu="@menu/navigation_menu">


    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

这是 app.Gradle.Build 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.example.branches.smartwashr"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.sdsmdg.harjot:longshadows:1.0.1'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha1'

}

请帮助我,因为这项工作对我来说非常重要,请帮助。抽屉布局无法正常工作

4

3 回答 3

1

尝试使用这个

<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:fitsSystemWindows="true"
    android:layout_gravity="start"
    tools:context=".Setting">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</android.support.constraint.ConstraintLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:headerLayout="@layout/header"
    app:menu="@menu/nav_menu"
    android:layout_gravity="start"
    android:fitsSystemWindows="true" />

</android.support.v4.widget.DrawerLayout>
于 2018-07-06T05:44:57.080 回答
0
// this is the name of file navigation_menu.xml//
//firstly you need to make a menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

        <item >
     //   here item related things like id and title

        </item>
        <item >
          //   here item related things like id and title

        </item>



</menu>
//then you need to add this in drawer layout

//mainactivity.xml code


<android.support.v4.widget.DrawerLayout>

 //first you take navigation menu and then perform the below process
  //in  android id tag you can add menu bar and you need to add two dependency
//dependency some
  //implementation 'com.android.support:design:27.1.1'
  // implementation 'com.android.support:support-compat:27.1.1'
https://www.youtube.com/watch?v=AS92bq3XxkA


//




</android.support.v4.widget.DrawerLayout>


 till you get some problem you can go on the below link
于 2018-07-06T14:10:01.133 回答
0

添加这个

dependencies {
    implementation "androidx.drawerlayout:drawerlayout:1.1.1"
}

在 build.gradle 文件中。文档

于 2021-05-05T15:53:27.367 回答