2012-03-15 21 views
1

Buttonsを同じ行に並べて、EditTextの隣にButtonを1つ置きたいと考えています。同じ行の複数のボタン/オブジェクト

私はEclipseアドオンを持っているので、グラフィカルレイアウトとテキストの両方があります。画像を投稿することはできませんが、それを記述します:にはTextViews(無関係)が2つ、EditTextが続き、次の行に小さいラベルなしButtonが続きます。次の4行は、電源を入れNラベルされたボタンがあり、Eを回し、Sを回して、次のようEditTextに、そうW.

を回し、私がすること無題Buttonを配置したい場所である、と私はNが欲しい、E、S 、W Buttonsをコンパスのように設定することができます。しかし、GUI上でそれらをドラッグしようとすると、行にバインドされ、レイアウトを変更しようとするたびに、右クリックしているオブジェクトだけでなく、すべてに影響します。

これを修正するにはどうすればよいですか?

答えて

1

何かこのような親の右側と下:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@id/textView1" 
     android:text="TextView" /> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@id/textView2" 
     android:layout_toLeftOf="@+id/button1" > 
    </EditText> 

    <Button 
     android:id="@id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_below="@id/textView2" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/editText1" 
     android:layout_centerHorizontal="true" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button2" 
     android:layout_toLeftOf="@id/button2" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button2" 
     android:layout_toRightOf="@id/button2" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button4" 
     android:layout_toLeftOf="@id/button4" 
     android:text="Button" /> 

</RelativeLayout> 
+0

おかげで、これは非常に有用だった、と今でXMLの私のグラフィカルなレイアウトビューは、私はそれがしたいだけのようにそれを表示しています。 (私はいくつかのボタンを追加しました)しかし、私のJavaファイルには、メインを参照するすべてのものにエラーがあります。 「setContentView(R.layout.main);」の下にあります。エラーが表示されます:「メインは解決できないか、フィールドではありません」私のXMLファイルにはエラーが表示されず、Eclipseを再起動しようとしましたが、何か問題が見つかりません。助言がありますか?ありがとう! – Zeldarulah

+0

@Zeldarulahあなたのプロジェクト(メニュー 'Project-> Clean')をきれいにして、あなたのパッケージから(' CTRL + SHIFT + O'を使って) 'R'クラスをインポートしたかどうかを確認してください。 R; ')。 – Luksprog

+0

私は "import android.R;"を持っていますが、Project - > CleanとCTRL + Shift + Oの両方を試しましたが、変更はありませんでした。 "android.R;をインポートする"何か違う?再度、感謝します。 – Zeldarulah

0

私は本当にxmlなしではそれについて言えませんが、コンパスのような方法でボタンを配置したい場合は、四辺形の相対レイアウトを作成し、ボタンを配置してから、 、

関連する問題