gpt4 book ai didi

android - 实现父子双方的可点击 View

转载 作者:行者123 更新时间:2023-11-30 03:22:11 26 4
gpt4 key购买 nike

我有一个可点击的 Relativelayout。我在其中有一个元素(ImageButton),我也希望它是可点击的。

在我添加 ImageButton 之前,布局是可点击的;现在只有那个是可点击的。

我已经在两个元素中尝试了 focusablefocusableInTouchMode = truefalse 的所有组合(我试过仅在 xml 布局中)。我怎样才能让它们都可以点击?

我的代码;请注意,这是在 ListView 中,每一行都有这个;周围有一个不可点击的 LinearLayout:

    <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/row_selector"
android:duplicateParentState="true"
android:paddingBottom="10dp" >

// several TextViews edited out

<ImageButton
android:id="@+id/ibMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@color/row_overflow_state"
android:contentDescription="menu"
android:src="@drawable/ic_action_overflow" />
</RelativeLayout>

最佳答案

用这个给你的 parent

android:addStatesFromChildren="true"

如果使用这个那么不要使用下面的否则你会得到stuck overflow exception

给你的 child 设置这个怎么样

android:duplicateParentState="true"

关于android - 实现父子双方的可点击 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18935184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com