我的应用程序无法运行,因为我的 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="horizontal"
,就像你上面做的一样。
关于android - 未指定方向,默认为水平方向。这是动态添加子项时常见的错误来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22098143/