具有ImageButton可聚焦性的ListView

时间:2015-11-21 10:40:38

标签: android android-listview focus android-imagebutton

我有一个带有TextView和ImageButton的ListView。

Screenshot

ListView有OnItemClickListener(),而ImageButton可能有OnClickListener(),也可能没有。{/ p>

下面是我的layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">

<com.bolo.customview.CustomTextViewLight
    android:id="@+id/textview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/contacts_friends_chat_button"
    android:textColor="@color/text_color_primary"
    android:textSize="@dimen/friend_name"/>

<ImageButton
    android:id="@+id/imagebutton"
    android:layout_width="@dimen/sixtyfour"
    android:layout_height="@dimen/sixtyfour"
    android:layout_alignParentRight="true"/>

</RelativeLayout>

有时我将ImageButton的可见性设置为VISIBLE,有时甚至是INVISIBLE。

以下是我想要完成的事情。

  1. 如果ImageButton具有onclicklistener,则ImageButton应捕获ImageButton上的单击,ListView应捕获该区域其余部分的单击。目前运行良好。

  2. 如果ImageButton没有onClickListener(ImageButton看起来可见并不重要),那么ImageButton应该永远不会捕获click事件。 ListView应捕获所有单击事件(在ImageButton和区域的其余部分)。目前这种情况并没有发生。当ImageButton是VISIBLE时,它会捕获click事件。

  3. 怎么做?请帮帮我。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你可以试试:

制作您不希望发生点击事件的按钮:clickable = false。

或者如果您不希望点击在不可见时发生,您可以将imageButton可见性设置为GONE而不是INVISIBLE。