0

我正在编写一个应用程序来控制机器人来控制 我 需要
(上、下、右、左) 键这个在屏幕中央? 有没有更好的方法在 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 回答