0

制御用のロボット
を制御するアプリケーションを作成しています (上、下、右、左) キーが必要です
Eclipse デザイナーを使用して作成しましたが、おそらくそれは不可能
です このようなものを作成したい :
矢印キー
どのようにボタンを作成できますかこれは画面中央?
Androidで矢印キーを作成するより良い方法はありますか?

4

2 に答える 2

3

どうぞ :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<View
    android:id="@+id/view1"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/view1"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/view1"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/view1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/view1"
    android:src="@drawable/ic_launcher" />

</RelativeLayout>

もちろん、ImageView を ImageButton のようなものに置き換えることができます。最初のビューの名前を変更した場合は、4 ImageView の名前を更新してください。また、各画像の角が互いに重なっていることに注意してください。

于 2013-06-22T18:05:53.273 に答える
1

ImageButtons を使用し、それぞれの背景を State List Drawable xml ファイルに設定することをお勧めします。これにより、状態 (フォーカス、プレスなど) の間で画像が変更されます。

トリッキーな部分は、上にあるこの種の「ボックス」に自分自身を向けるようにそれぞれを配置することです.

各ボタンの PNG をそれぞれの位置に作成するだけです。上ボタンは上向き、左向きは左向きなどです。次に、RelativeLayout を使用してそれらを相互に配置します。ボタンも使用できます

于 2013-06-22T18:00:39.010 に答える