child clickable/parent 可长按
child clickable/parent longclickable
我有一个 FrameLayout
里面有 TextView
。
<FrameLayout
android:id="@+id/fl_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:autoLink="email|web|phone"/>
</FrameLayout>
我的 TextView
为 email/web/phone 启用了自动链接,如您所见。但是我的 FrameLayout
在代码中有 LongClickListener
。
flContainer.setOnLongClickListener {
// some work
}
但是当我尝试通过 child TextView 长按到 parent FL 时,它不起作用,因为 TV 拦截点击并且不允许 parent 获得长按.
我知道简单的解决方案 - 只需将相同的 longClickListener 应用于 TextView,但我的 FL 上有 android:background="?attr/selectableItemBackground"
,因此当我单击它时它应该会产生连锁反应,但电视会消耗它。有可能实现吗?
在父布局中使用 android:addStatesFromChildren="true"
。如文档中所述,
Sets whether this ViewGroup's drawable states also include its
children's drawable states. This is used, for example, to make a group
appear to be focused when its child EditText or button is focused.
您可以在这里找到它:
我有一个 FrameLayout
里面有 TextView
。
<FrameLayout
android:id="@+id/fl_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:autoLink="email|web|phone"/>
</FrameLayout>
我的 TextView
为 email/web/phone 启用了自动链接,如您所见。但是我的 FrameLayout
在代码中有 LongClickListener
。
flContainer.setOnLongClickListener {
// some work
}
但是当我尝试通过 child TextView 长按到 parent FL 时,它不起作用,因为 TV 拦截点击并且不允许 parent 获得长按.
我知道简单的解决方案 - 只需将相同的 longClickListener 应用于 TextView,但我的 FL 上有 android:background="?attr/selectableItemBackground"
,因此当我单击它时它应该会产生连锁反应,但电视会消耗它。有可能实现吗?
在父布局中使用 android:addStatesFromChildren="true"
。如文档中所述,
Sets whether this ViewGroup's drawable states also include its children's drawable states. This is used, for example, to make a group appear to be focused when its child EditText or button is focused.
您可以在这里找到它: