Android layout 下一行的Android输入框

Android layout 下一行的Android输入框,android-layout,Android Layout,好的,所以我决定参加谷歌学习机器人脱衣课程。我决定不使用简单的输入框和按钮,而是制作多个输入框和按钮,每个输入框和按钮都显示一组颜色。问题在于,它将所有输入框卡在一条线上,而不是它们自己的单独线路上。这是我在activity_color.xml中看到的内容 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

好的,所以我决定参加谷歌学习机器人脱衣课程。我决定不使用简单的输入框和按钮,而是制作多个输入框和按钮,每个输入框和按钮都显示一组颜色。问题在于,它将所有输入框卡在一条线上,而不是它们自己的单独线路上。这是我在activity_color.xml中看到的内容

<?xml version="1.0" encoding="utf-8"?>
<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="horizontal" >

<EditText android:id="@+id/edit_message_blue"
    android:layout_width="0dp"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:hint="@string/edit_message_blue" />


<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send_blue" 
    android:onClick="sendMessageBlue" />

<EditText android:id="@+id/edit_message_orange"
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:hint="@string/edit_message_orange" />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/button_send_orange" 
    android:onClick="sendMessageOrange" />

</LinearLayout>
现在我想问题是如何告诉它开始一个新的行,比如android:layout_next=“1”或其他什么(我知道它不存在),或者我必须添加到公共类中?例如制作另一个布局文件并引用该文件?我非常怀疑后者会起作用

编辑:根据列出的说明,我想我应该这样做,但它只知道第一行:(


您的父布局设置为
android:orientation=“horizontal”
。这需要设置为
android:orientation=“vertical”

编辑:以下是Android文档中的参考:

当我更改没有显示任何输入框时,只有“发送”按钮,但按钮的方向是正确的:DEdit:我不知道按钮现在在输入框下面。我去掉了weight=“1”因为我不相信它适用于垂直,并且喜欢宽度匹配的结果,但我不喜欢下面的按钮。当然有一种方法可以使水平,一行上有一个输入框和按钮,下一行上有一个输入框和按钮。绝对。你可以在主L中嵌套水平方向的线性布局因此,对于每一个编辑文本/按钮组合,您可以让它们水平排列,并且每个子线性布局将垂直排列。或者,您可以考虑使用表列并将每个编辑文本/按钮放在列表中。在每个孩子中,线性布局元素将高度更改为<代码> Android:Layo。ut\u height=“wrap\u content”DOH!!我现在感觉自己像个笨蛋,哈哈,这是多么简单的错误。它按预期工作。非常爱你和这个精彩的网站:D
package com.example.color.texts;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class ColorTexts extends Activity {
public final static String EXTRA_MESSAGE = "com.example.colortexts.MESSAGE";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_color_texts);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_color_texts, menu);
    return true;
}

/** Called when the user clicks the Send button for Blue */
public void sendMessageBlue(View view) {
    Intent intent = new Intent (this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message_blue);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}

/** Called when the user clicks the Send button for Red */
public void sendMessageRed(View view) {
    Intent intent = new Intent (this, DisplayMessageActivityRed.class);
    EditText editText = (EditText) findViewById(R.id.edit_message_red);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}


/** Called when the user clicks the Send button for Orange */
public void sendMessageOrange(View view) {
    Intent intent = new Intent (this, DisplayMessageActivityOrange.class);
    EditText editText = (EditText) findViewById(R.id.edit_message_orange);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);

}
}
<?xml version="1.0" encoding="utf-8"?>
<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" >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText android:id="@+id/edit_message_blue"
    android:layout_width="0dp"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:hint="@string/edit_message_blue" />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send_blue" 
    android:onClick="sendMessageBlue" />

</LinearLayout>

<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="horizontal" >    

<EditText android:id="@+id/edit_message_red"
    android:layout_width="0dp" 
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:hint="@string/edit_message_red" />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/button_send_red" 
    android:onClick="sendMessageRed" />

</LinearLayout>

<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="horizontal" >

<EditText android:id="@+id/edit_message_orange"
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:hint="@string/edit_message_orange" />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/button_send_orange" 
    android:onClick="sendMessageOrange" />

</LinearLayout>

</LinearLayout>