Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android UI元素并排显示。不自上而下_Android_User Interface - Fatal编程技术网

Android UI元素并排显示。不自上而下

Android UI元素并排显示。不自上而下,android,user-interface,Android,User Interface,我遵循教程学习Android开发。我面临一个关于如何在屏幕上显示控件的问题 如果您查看该教程中的屏幕截图,所有UI元素都以堆叠的方式一个接一个地显示在屏幕上。但当我这样做的时候,它看起来是这样的 肖像画 正如您所看到的,只有几个元素显示在可见的屏幕空间中。其余的在屏幕右侧。如果我把屏幕转到横向,它们就在那里 这是我的activity\u main.xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/

我遵循教程学习Android开发。我面临一个关于如何在屏幕上显示控件的问题

如果您查看该教程中的屏幕截图,所有UI元素都以堆叠的方式一个接一个地显示在屏幕上。但当我这样做的时候,它看起来是这样的

肖像画

正如您所看到的,只有几个元素显示在可见的屏幕空间中。其余的在屏幕右侧。如果我把屏幕转到横向,它们就在那里

这是我的
activity\u main.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" >

    <TextView
        android:id="@+id/main_textview"
        android:text="@string/textview"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/main_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:text="@string/button" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:src="@drawable/ic_launcher" />

        </LinearLayout>

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

    <ListView
        android:id="@+id/main_listview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="20dp" />

</LinearLayout>

所有内容都按照教程所述编写

然而,在本教程中,他们使用模拟器来运行它。我正在使用一个测试工具。但我在同一个模拟器中运行了这个应用程序,但我仍然面临着这个确切的问题

谁能告诉我我可能做错了什么以及如何纠正它


谢谢。

线性布局需要关于适当方向的声明


android:orientation=“垂直”

线性布局需要关于适当方向的声明


android:orientation=“垂直”

您的布局应如下所示:

    <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:orientation="vertical" >  <!--here vertical-->

<TextView
    android:id="@+id/main_textview"
    android:text="@string/textview"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >   <!--here vertical-->

    <Button
        android:id="@+id/main_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/button" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:src="@drawable/ic_launcher" />

    </LinearLayout>

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

<ListView
    android:id="@+id/main_listview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_marginTop="20dp" />


您的布局应如下所示:

    <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:orientation="vertical" >  <!--here vertical-->

<TextView
    android:id="@+id/main_textview"
    android:text="@string/textview"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >   <!--here vertical-->

    <Button
        android:id="@+id/main_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/button" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:src="@drawable/ic_launcher" />

    </LinearLayout>

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

<ListView
    android:id="@+id/main_listview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_marginTop="20dp" />


您应该定义线性布局的方向。

您应该定义线性布局的方向。

使用
android:orientation=“vertical”

要垂直设置布局视图

请参阅链接以了解方向更改的基本区别

使用
android:orientation=“vertical”

要垂直设置布局视图


请参阅链接以了解方向更改的基本区别

android:orientation=“vertical”
设置为您的
LinearLayout
您的家长
LinearLayout
没有
orientation
set
android:orientation=“vertical”
到您的
线性布局
您的父母
线性布局
没有
方向
或使用示例学习…或使用示例学习。。。