OnTouchListener不适用于相对布局

穆罕默德·乌马尔:

RelativeLayout在其中TextViews动态添加了许多内容我面临的问题是,每当我TextViews单独将onTouch侦听器应用于其时,它都会检测到触摸,但是当我向相对布局中添加触摸时,它永远不会响应。

此代码可以很好地检测触摸事件:

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

但是,当我在myRelativeLayout中添加所有这些TextViews时:

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>
穆罕默德·乌马尔:
tv.setClickable(true);

导致您的布局,而不是触发触摸事件。尝试删除它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章