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

我的应用程序无法运行,因为我的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块中添加android:orientation =“horizo​​ntal”,与上面的操作相同.

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...