我在右上角放置了一个小ImageButton
,后面有一个Button
,包裹了所有内容。
我认为正常行为可能是当触摸小ImageButton
时,它会接收到触摸。但目前的行为是,当它被触摸时,就像不存在一样,并将触摸传递给后面的按钮。
我尝试使用android:clickable
属性,将ImageButton
小FrameLayout
放入android:clickable="true"
,还有很多其他内容。
这是一个选中了两个元素的图像,以及.xml。我认为这不是一件非常复杂的事情,但我不知道自己做错了什么。
谢谢大家。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ivBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/club_placeholder" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="1"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold"
android:layout_centerInParent="true" />
<Button
android:id="@+id/btBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_tab"
android:layout_alignLeft="@+id/ivBackground"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/ivBackground" />
<ImageButton
android:id="@+id/btFavorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_tab"
android:padding="15dp"
android:src="@drawable/ic_favorite_border_white_24dp"
android:clickable="true"
android:contentDescription="Favorite"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
答案 0 :(得分:1)
我认为你的Button的高度比ImageButton高。 实际上,如果为背景按钮设置颜色,则不会看到喜欢的图像按钮。因此,将Button更改为ImageButton可以解决问题。
点击此链接:stackoverflow thread
我希望这可以帮到你;)