0

よくわかりません。地図を表示したいのですが、地図の下に5つのボタンが表示されます。私は RelativeLayout を使用していますが、プログラムは製品ボタンを表示するだけです。なんで?どのレイアウトを使用するか(線形、相対、フレーム、または絶対)混乱しています!! 私を助けてください。このコードを修正するにはどうすればよいですか?

location.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:apiKey="0cPRv243zM1_S3ydsNg8MJP9_6BfCp642jOhPvQ"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/background"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button_home"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/home_icon"
        android:text="@string/button_home"
        android:textColor="@color/text_home" />

     <Button
        android:id="@+id/button_product"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/product_icon"
        android:onClick="Product"
        android:text="@string/button_product"
        android:textColor="@color/text_product" />

  </LinearLayout>
  </LinearLayout>
4

3 に答える 3

1

特定の問題に答えるには: ホーム ボタンが製品ボタンの左側にあると言う代わりに、製品ボタンがホーム ボタンの右側にあると言う必要があります。RelativeLayout がインフレートされると、レイアウトは直線的に解析されるため、ビュー A がビュー B に対して相対的に配置されている場合、ビュー B が最初に来る必要があります。

<Button
    android:id="@+id/button_home"
    style="?android:attr/borderlessButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/home_icon"
    android:text="@string/button_home"
    android:textColor="@color/text_home"/>

<Button
    android:id="@+id/button_product"
    style="?android:attr/borderlessButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/button_home"
    android:drawableTop="@drawable/product_icon"
    android:onClick="Product"
    android:text="@string/button_product"
    android:textColor="@color/text_product" />

これをプロダクト ボタンに追加し、ホーム ボタンから layout_toLeftOf を削除します。

    android:layout_toRightOf="@id/button_home"

重力と位置合わせを使用してホーム ボタンを配置し、その後に他の 4 つのボタンを配置し、それぞれを前のボタンの右側に配置できます。

幸運を

于 2012-11-01T07:29:31.503 に答える
0

RelativeLayout はデフォルトでこれら 2 つのボタンを一緒に配置するため、後者だけが表示されます。

そしてライン

android:layout_toLeftOf="@+id/button_product"

間違っている。@+idid を作成します@id。このような場合に使用します。

状況には LinearLayout をお勧めします。これらのボタンをその中に配置し、マージンをとって調整します。

于 2012-11-01T07:25:05.803 に答える
0
  • LinearLayout : LinearLayout は、ウィジェット/ビューを水平または垂直に配置する必要がある場合に使用されます。配置の方向は、横または縦に設定できます。デフォルトでは横になっています。

  • TableLayout : レイアウトのウィジェット/ビューを行と列の形式で配置する必要がある場合は、このレイアウト オブジェクトを使用します。これは、html テーブルに似ています。セルは複数の列にまたがることができます。TableLayout は境界線を表示しません。列のそれぞれのプロパティを設定することで、縮小と拡大を行うことができます。「TableRow」は、TableLayout と組み合わせて使用​​する必要がある別のヘルパー ウィジェットです。

  • RelativeLayout : ここでは、各ウィジェット/ビューの位置が互いに相対的/依存しています。たとえば、Edit Textbox のすぐ左にテキスト ビューがあり、EditText のすぐ下にボタンがあるようなレイアウトが必要な場合です。ビュー間の関係は 1 回の反復で処理されるため、ビュー B の位置がビュー A の位置に依存している場合、ビュー A がレイアウトで最初に来る必要があります。

  • FrameLayout : これは非常に単純なレイアウトで、実行時に項目または項目のグループを表示するために画面の一部を空白にするために使用されます。フレームレイアウトに追加されたすべての要素が画面の左上に追加されます。

  • AbsoluteLayout : ビューの正確な x および y 座標位置を指定する必要がある場合は、AbsoluteLayout を使用する必要があります。このレイアウトは維持するのが難しいです。

于 2012-11-01T07:20:32.080 に答える