2012-08-30 3 views
0

좋아, 그래서 드로 이드 devving 학습을위한 Google 수업을하기로 결정했습니다. 나는 단순한 입력 상자와 버튼 대신에 여러개의 버튼을 만들고 각각이 설정된 색상을 표시하도록 결정했다. 문제는 각 입력 상자가 각기 다른 줄이 아니라 한 줄에 끼어 들게된다는 것입니다. 이것은이안드로이드 입력란 다음 줄에

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

} 
} 

지금 내가 질문 하나 안드로이드처럼, 새 줄을 시작하도록 지시하는 방법을 추측 주요 자바 클래스 I는 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> 

에있는 것입니다 : 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> 

답변

1

당신의 부모 레이아웃이 android:orientation="horizontal"로 설정되어 :(첫 선을 보여줍니다. 이것은 android:orientation="vertical"로 설정해야

편집

:. 여기 안드로이드 문서의 기준이다 http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:orientation

+0

I 변경할 때 입력 B의 안됨 황소가 나타나지만 버튼의 방향은 정확합니다. D – TheMik

+0

편집 : 단추가 입력 상자 아래에 있다는 사실을 알 수 없습니다. 나는 그것이 vertical에 적용된다고 믿지 않기 때문에 weight = "1"을 없앴다. width에 match_parent의 결과처럼, 그러나 나는 아래의 버튼을 좋아하지 않는다. 확실히 하나의 입력 상자와 버튼을 한 줄에두고 다음 입력 상자와 버튼을 사용하여 수평을 만드는 방법이 있습니다. – TheMik

+0

물론입니다. LinearLayout을 메인 LinearLayout 내에 수평 방향으로 네 스팅 할 수 있습니다. 따라서 각 EditText/Button 조합에 대해 수평으로 배치 할 수 있으며, 각각의 자식 LinearLayout은 수직으로 배치됩니다. TableLayout을 사용하고 각 EditText/Button을 TableRow 내부에 배치하는 것도 고려해 볼 수 있습니다. – japino

관련 문제