英文:
Element LinearLayout Not Allowed Here
问题
我在我的AndroidManifest.xml文件中收到错误消息:元素LinearLayout在此处不允许。
我已经尝试重新启动Android Studio,但没有任何效果。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXXX"></meta-data>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_lng"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</application>
</manifest>
为什么我会收到这个警告?
英文:
I'm getting the error Element LinearLayout is not allowed here in my AndroidManifest.xml file.
I've tried restarting Android studio, but that hasn't had any effect.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXXX"></meta-data>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_lng"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</application>
</manifest>
Why am I getting this warning?
答案1
得分: 1
你不能在清单文件中定义布局信息。清单文件用于描述应用程序,例如应用程序使用的权限和应用程序中存在的活动。
你最可能想要做的是打开你的 activity_main.xml
并将你的布局添加到其中。
请参考布局指南,了解如何入门,该指南来自Android开发者文档。
另外,要获取有关清单文件用途的更多信息,请参阅清单文件文档。
要开始操作,你需要将XML拆分成适当的文件:
androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXX"></meta-data>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/container"
android:orientation="vertical">
<TextView
android:id="@+id/tv_lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_lng"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
英文:
You can't define layout information in your Manifest. The Manifest is meant to describe the application, like which permissions the app uses and which activities reside in your app.
What you're most likely want to do, is open you activity_main.xml
and Add your layout to that.
Please refer to layout guide from the Android Developers documentation on how to get started.
Also for more information on what the Manifest is meant for, refer to the Manifest Documentation.
What you'll want to do to get started, is split the xml in the the appropriate files:
androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="XXXXXXXXXXXXXXXXXXX"></meta-data>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/container"
android:orientation="vertical">
<TextView
android:id="@+id/tv_lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_lng"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论