以下は、jetboyサンプルAndroidアプリのタッチスクリーンを使用して動作します。Joesコードは、1つの調整で機能し、背景を照らします。私が追加した唯一の行は
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>