よし、ドロイド開発を学ぶために Google のクラスを受講することにした。単純な入力ボックスとボタンの代わりに、複数のものを作成し、それぞれに色を設定することにしました。問題は、すべての入力ボックスが個別の行ではなく、1 つの行に詰まっていることです。これは私が 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>