RecyclerView上的多个根标签

时间:2017-04-18 09:23:42

标签: android xml tags root

我在Android Studio中使用Android应用,遇到了错误:“多根标签”

我的申请代码:

<? 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: layout_width =" match_parent 
"android: orientation =" vertical 
"android: layout_height =" match_parent 
"android: paddingLeft =" @ dimen / activity_horizontal_margin 
"android: paddingRight =" @ dimen / activity_horizontal_margin 
"android: paddingTop = "@ dimen / activity_vertical_margin" android: paddingBottom = "@ dimen / activity_vertical_margin" tools: context = ". MainActivity">

    <Android.support.v7.widget.RecyclerView 
android: id = "@ + id / recyclerView" 
android: layout_width = "wrap_content" 
android: layout_height = "wrap_content" 
android: layout_marginLeft = "20dp" 
android: paddingLeft = "40dp"> 
</android.support.v7.widget.RecyclerView>

</ LinearLayout>

... 如何解决这个错误之手? 感谢

2 个答案:

答案 0 :(得分:1)

<?Xml version = "1.0" encoding = "utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.comtools" 
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:paddingLeft="40dp" />

</ LinearLayout>

答案 1 :(得分:0)

您的XML代码有很多错误和不必要的空间,不允许Android Studio正确理解您的需求,并且无法解析您的Android和工具标记。此外,您对RecyclerView的声明是错误的。

我更新了你的XML,删除了不必要的空格并修复了RecyclerView的声明。

<?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:layout_width="match_parent"
    android:layout_height=" match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:paddingLeft="40dp" />

</ LinearLayout>