私は動的にRelativeLayout
多くを追加しています。TextViews
私が直面している問題は、onTouch リスナーをTextViews
個別に適用するたびにタッチが検出されますが、相対レイアウトにタッチを追加すると応答しないことです。
このコードは、タッチ イベントを正常に検出します。
TextView tv = new TextView(this);
tv.setText(values[i]);
Drawable d = getResources().getDrawable(R.drawable.level_small_corners);
tv.setClickable(true);
tv.setId(i+1);
tv.setTextSize(18);
tv.setOnTouchListener(cellTouch);
しかし、これらすべての TextView を myRelativeLayout に追加すると、次のようになります。
myRelativeLayout.setOnTouchListener(cellTouch);
これで、onTouchListener が呼び出されることはありません。どうしてこんなことに?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black">
.
.
.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/levelFirstLayout"
android:layout_marginBottom="70dp" >
<RelativeLayou
android:id="@+id/wordsRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true" >
</RelativeLayout>
</ScrollView>
.
.
.
</RelativeLayout>