android - 未指定方向,默认为水平方向。这是动态添加子项时常见的错误来源

标签 android xml

我的应用程序无法运行,因为我的 xml 文件中存在错误。我的一个 LinearLayouts 被标记为红色,通过悬停我可以看到以下错误消息: 未指定方向,默认为水平方向。这是动态添加子项时常见的错误来源。

您可以在下面看到我的代码,如果我收到此消息,我将标记该行,如下所示: <- 错误信息 ->

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        >
        <Button 
            android:id="@+id/btn1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Fragment 1"
            />

        <Button 
            android:id="@+id/btn2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Fragment 2"
            />

        <Button 
            android:id="@+id/btn3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Fragment 3"
            />

    </LinearLayout>

    <LinearLayout             <- error message -> 
        android:id="@+id/myFragment"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="3" />


</LinearLayout>

最佳答案

你应该在 LinearLayout block 中添加 android:orientation="horizo​​ntal",就像你上面做的一样。

关于android - 未指定方向,默认为水平方向。这是动态添加子项时常见的错误来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22098143/

相关文章:

android - 在多台机器上使用 Android 模拟器图像

android - 我想让打开侧边栏时的 Activity 变小?

java - 在标准 Java 中迭代 XML DOM 文档

Android View 和自定义方向更改,最好的处理方式是什么?

android - 在默认的 intent-app 中设置应用程序

android - 基于 Android Tab 的 Activity 中的 LogCat 错误 “you must specify a way to create tab indicator”

c# - XmlElement 到字符串的转换

sql - SQL Server 中带有 XML 列的临时表

xml - 在 VB6 中检索 WinHttpReq.ResponseBody 跳过的热链接页面数据的最佳方法

regex - XSD 模式限制 - 与正斜杠交替