首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在这行找到多个注释:第一个程序Android Programming_ The Big Nerd Ranch Guide f

在这行找到多个注释:第一个程序Android Programming_ The Big Nerd Ranch Guide f
EN

Stack Overflow用户
提问于 2013-12-27 12:08:25
回答 3查看 3.6K关注 0票数 0

我从Android Programming_的“大书呆子农场指南”一书中复制了第一个程序。我得到了下面的错误。在此行找到多个批注:- error:在文档元素后解析XML时出错: junk -文档中跟在根元素后面的标记必须是格式正确的。在第16行,下面是我的代码

代码语言:javascript
复制
<RelativeLayout 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"
tools:context=".QuizActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world" />

</RelativeLayout>

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

android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"  >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="24dp"
    android:text="@string/question_text" />

<LinearLayout
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    andriod:orientation="horizontal" >
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/true_button" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/false_button"   />

</LinearLayout>

</LinearLayout>
EN

回答 3

Stack Overflow用户

发布于 2013-12-27 12:24:25

您正尝试在同一个xml中使用两个父布局。这在Android中是不可能的。在这种情况下,使用RelativeLayoutLinearLayout作为父对象。

使用此模板:

代码语言:javascript
复制
<RelativeLayout
    //relative layout attributes
    >
    //you can add as many as elements here

    <LinearLayout
        //linear layout attributes
        >
        //you can add as many as elements here
    </LinearLayout>
</RelativeLayout>

如果您想同时使用RelativeLayoutLinearLayout,请在xml文件中添加单独的父布局,如下所示:

代码语言:javascript
复制
<RalativeLayout
    //this is your main parent layout
    >

    //Add as many as Linear/Relative layout here doesn't matter.

</RelativeLayout>
票数 1
EN

Stack Overflow用户

发布于 2013-12-27 12:13:28

更改布局:您正尝试为一个xml文件初始化两个独立的布局。使用一个主布局&您可以使用其他布局作为其子布局。

代码语言:javascript
复制
<RelativeLayout 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"
tools:context=".QuizActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world" />



<LinearLayout 

android:layout_width="match_parent"
android:layout_height="match_parent"
 //u can specify `below` , `above` property as per your need
android:gravity="center"
android:orientation="vertical"  >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="24dp"
    android:text="@string/question_text" />

<LinearLayout
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    andriod:orientation="horizontal" >
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/true_button" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/false_button"   />

</LinearLayout>

</LinearLayout>
</RelativeLayout>
票数 0
EN

Stack Overflow用户

发布于 2013-12-27 13:43:50

代码语言:javascript
复制
// try this way
<?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:gravity="center"
    android:orientation="vertical"
    tools:context=".QuizActivity"  >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="@string/question_text" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/true_button" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"   />

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

https://stackoverflow.com/questions/20794588

复制
相关文章

相似问题

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