首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何声明我的LinearLayout元素?

如何声明我的LinearLayout元素?
EN

Stack Overflow用户
提问于 2019-02-19 04:23:37
回答 1查看 526关注 0票数 0

在我的集成开发环境中,LinearLayout-tag被标记为红色,错误消息为:"Element LinearLayout must be declared"。我的目录设置如下:

https://imgur.com/a/deneVxN

activity_main.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">


<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_first_fragment"
            android:icon="@drawable/ic_1"
            android:title="First"
            tools:ignore="HardcodedText" />
        <item
            android:id="@+id/nav_second_fragment"
            android:icon="@drawable/ic_2"
            android:title="Second"
            tools:ignore="HardcodedText" />
        <item
            android:id="@+id/nav_third_fragment"
            android:icon="@drawable/ic_3"
            android:title="Third"
            tools:ignore="HardcodedText" />
    </group>
</menu>

</LinearLayout>

activity_main.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout     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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">



<ImageButton
    android:id="@+id/twitchBtn"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="124dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:adjustViewBounds="true"
    android:cropToPadding="true"
    android:scaleType="centerInside"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.496"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/twitch" />

<ImageButton
    android:id="@+id/youtubeBtn"
    android:layout_width="253dp"
    android:layout_height="249dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:adjustViewBounds="true"
    android:cropToPadding="true"
    android:scaleType="centerInside"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/twitchBtn"
    app:layout_constraintVertical_bias="0.336"
    app:srcCompat="@drawable/youtube" />


<TextView
    android:id="@+id/textPlattform"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="36dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:text="Choose platform"
    android:textAppearance="@style/TextAppearance.AppCompat"
    android:textSize="38sp"
    app:fontFamily="sans-serif"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<!-- This DrawerLayout has two children at the root  -->
<android.support.v4.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">
    <!-- The navigation drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_weight="1"
        android:background="@android:color/white"
        app:menu="@menu/drawer_view.xml"/>

    <!-- This LinearLayout represents the contents of the screen  -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- The ActionBar displayed at the top -->
        <include
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <!-- The main content view where fragments are loaded -->
        <FrameLayout
            android:id="@+id/flContent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>


   </android.support.v4.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

我想要获得一个汉堡菜单,我正在学习这个教程:https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer,但是如果我现在运行这个程序,我会得到一个NullPointerExeption,但我认为这是因为drawer_view.xml不能工作。

EN

回答 1

Stack Overflow用户

发布于 2019-02-19 04:44:06

是因为drawer_view.xml的定义是错误的

drawer_view.xml是

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_first_fragment"
            android:icon="@drawable/ic_1"
            android:title="First"
            tools:ignore="HardcodedText" />
        <item
            android:id="@+id/nav_second_fragment"
            android:icon="@drawable/ic_2"
            android:title="Second"
            tools:ignore="HardcodedText" />
        <item
            android:id="@+id/nav_third_fragment"
            android:icon="@drawable/ic_3"
            android:title="Third"
            tools:ignore="HardcodedText" />
    </group>
</menu>

在activity_main.xml中,菜单不包含扩展.xml

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54754824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档