Android 活动都出现在同一行

Android activity's all appear on the same line

我在 Android Studio 中的 xml 代码有问题。

出于某种原因,此 xml 代码:

<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: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">

    <TextView
        android:id="@+id/main_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/textview"/>
    <!-- Set OnClickListener to trigger results when pressed -->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <!-- Displays keyboard when touched -->
    <EditText
        android:id="@+id/main_edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:hint="@string/hint" />
    <!-- This nested layout contains views of its own -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <!-- Set OnClickListener to trigger results when pressed -->
        <Button
            android:id="@+id/main_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:text="@string/button" />
        <!-- Shows an image from your drawable resources -->
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:src="@drawable/ic_launcher" />
        <!-- Closing tag for the horizontal nested layout -->
    </LinearLayout>
    <!-- Displays keyboard when touched -->

</LinearLayout>

当我运行我的应用程序时,所有出现在同一行。

如何让它像 html.

中的 br 标签一样转到下一行

感谢您的帮助!

你应该添加 android:orientation="vertical" 到第一个(外部)LinearLayout.

对于线性布局:

The default orientation is horizontal.

只需将主布局中的方向设置为:

android:orientation="vertical"

Documentation

线性布局

A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). You can also specify gravity, which specifies the alignment of all the child elements by calling setGravity() or specify that specific children grow to fill up any remaining space in the layout by setting the weight member of LinearLayout.LayoutParams. The default orientation is horizontal.

这就是为什么您将所有内容放在同一行上的原因。