使用觸摸屏上的噴氣男孩樣本Android應用程序下面的作品。 喬斯代碼與一個調整工作,使其閃耀背景。 我添加的唯一一條是
android:background="#0000"
android:layout_height="fill_parent"
android:layout_height="fill_parent"
感謝喬(上圖)。
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textView = (TextView)findViewById(R.id.textView);
// this is the view on which you will listen for touch events
final View touchView = findViewById(R.id.touchView);
touchView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
textView.setText("Touch coordinates : " +
String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
return true;
}
});
}
佈局代碼
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.android.samples.jetboy.JetBoyView android:id="@+id/JetBoyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/touchView"
android:background="#0000"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello World, TestActivity"
/>
</FrameLayout>
你可能想看看http://stackoverflow.com/questions/2068007/android-how爲我的另一種解決方案獲取原始觸摸屏信息。 – 2010-05-30 16:20:05
我試了一下你的代碼,並做了一些修正,但我可能無法讓它工作。感謝您抽出時間幫助我,即使我無法正常工作(這是我的錯,因爲我不知道Java) – Joe 2010-05-30 16:32:13
非常感謝:)這件作品很好吃 – Joe 2010-05-30 19:12:17