【发布时间】:2015-06-20 23:40:26
【问题描述】:
布局具有以下结构:
<LinearLayout
android:id="@+id/card_pack_clickable_area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/card_pack_bg_selector">
<FrameLayout
android:id="@+id/card_pack_body_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_card_pack_body">
<...>
</FrameLayout>
<TextView
android:id="@+id/card_pack_percentage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/bg_card_pack_body"/>
</LinearLayout>
@drawable/card_pack_bg_selector"的内容:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#536dfe" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#536dfe" />
</shape>
</item>
<item android:drawable="@android:color/transparent"/>
</selector>
问题陈述
所以 LinearLayout card_pack_clickable_area 有两个元素:FrameLayout card_pack_body_frame_layout 和 TextView card_pack_percentage。
我想要实现的是将 FrameLayout 和 TextView 作为单个可点击区域,这就是我将它们包装到外部 LinearLayout 中的原因。
在 Java 代码中,我在此 LinearLayout 上放置了 onClickListener。实际上,当我单击 FrameLayout 或 TextView 时,我正在获取 onClick 事件。
问题在于 LinearLayout 没有按照其背景 (@drawable/card_pack_bg_selector") 更改其状态。
问题
我怎样才能将 FrameLayout 和 TextView 作为具有单一背景的联合可点击区域,从而改变其按下/未按下状态?
【问题讨论】:
标签: android android-layout onclick