下一行的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>

这是主要的java类

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);
}
}

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

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

<?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>

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

编辑:以下是Android文档中的参考:http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:orientation

相关内容

最新更新