为了账号安全,请及时绑定邮箱和手机立即绑定

OnTouchListener 不能使用 relative layout

OnTouchListener 不能使用 relative layout

ABOUTYOU 2019-04-03 22:19:03
我在一个RelativeLayout中动态的添加了很多TextViews。我现在面临的问题是:不论什么时候当我单独申请一个 onTouch 监听器到TextViews,当我添加touch事件到relative layout时它能检测到touch 事件,但是没有回应。检测touch事件代码: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 添加所有的 TextViewsmyRelativeLayout.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"              >          <RelativeLayout                android:id="@+id/wordsRelativeLayout"              android:layout_width="fill_parent"               android:clickable="true"                 android:layout_height="wrap_content" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true"             >         </RelativeLayout>         </ScrollView>      .     .     .         </RelativeLayout>
查看完整描述

4 回答

?
慕容3067478

TA贡献1773条经验 获得超3个赞

问题出在 tv.setClickable(true);,删除这条语句。


查看完整回答
反对 回复 2019-04-28
?
红糖糍粑

TA贡献1815条经验 获得超6个赞

在 myRelativeLayout.xml 添加:

android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"


查看完整回答
反对 回复 2019-04-28
  • 4 回答
  • 0 关注
  • 634 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信