当前位置: 动力学知识库 > 问答 > 编程问答 >

android - creating arrow keys on center of screen

问题描述:

i am writing an application to control a robot

for controlling i need ( up, down , right, left ) keys

i used eclipse designer to create it but maybe it is not possible

i want to create something like this :


how can i create buttons like this in center of screen ?

is there a better way to create arrow keys on android ?

网友答案:

Here you go :

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

Of course, you can replace ImageView with anything else like an ImageButton. Be sure, if you change the name of the first view, tu update the name in the 4 ImageView. And be aware that the corners of each image are overlapping each other.

网友答案:

I suggest using ImageButtons and setting the background for each to a State List Drawable xml file. This will change the image between states(focused, pressed, etc).

The tricky part would be positioning each so that they orient themselves in this sort of "box" you have above.

Just create some PNGs of each button in their positions. Up button points up, left points left etc. Then use RelativeLayout to position them with respect to each other. You can also use Buttons as well

分享给朋友:
您可能感兴趣的文章:
随机阅读: