Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

android - Navigation View XML doesn't let me interact with anything else

I'm implementing a Navigation View on my activityHome for the first time. When i run the app and enter the home activity it function well. The problem is at the XML editor on the android studio, the Nav View is above all the other elements and doesn't let me click on them.

I haven't touch anything else but these yet. Thanks.

image of the problem

XML CODE:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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/dl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:fitsSystemWindows="true"
    tools:context=".activities.HomeActivity"
    tools:openDrawer="start">

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        android:background="@color/colorPrimary"
        app:menu="@menu/menu"
        tools:ignore="MissingConstraints" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageButton
        android:id="@+id/iv_menu"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="?android:selectableItemBackground"
        android:scaleType="centerInside"
        app:layout_constraintBottom_toTopOf="@+id/guideline46"
        app:layout_constraintEnd_toStartOf="@+id/guideline139"
        app:layout_constraintStart_toStartOf="@+id/guideline135"
        app:layout_constraintTop_toTopOf="@+id/guideline45"
        android:elevation="10dp"
        app:srcCompat="@drawable/menubuttonofthreelines_79781" />
...

and continues with the other elements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your layout has nothing wrong..

The reason that Android Studio shows that the drawer layout in the Open state in the design view because you set tools:openDrawer="start" in the DrawerLayout .. if you want to see the main layout in the design mode (i.e. to make the drawer in the close state), then you need to remove this attribute.

This attribute won't affect the looking of your app when you launch it.

Documentation:

You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.

XML tools namespace is just used to show you some behavior on Android Studio, but not while you run the app. Please check documentation for more info


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...