2013-08-28 96 views
0

我有這段小小的代碼,我開始使用相對佈局,並且textview不再可點擊。如果有人能夠提出修復建議,那將會很棒。我張貼下面的XML。Android TextView不可點擊

<?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="wrap_content" 
android:background="@drawable/fav_list_selector" 
android:orientation="horizontal" 
android:padding="5dip">  
<ImageButton 
    android:id="@+id/pinImage" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/ic_9_av_make_available_offline" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"/>  
<TextView 
    android:id="@+id/favBusItem" 
    android:layout_toRightOf="@+id/pinImage" 
    android:layout_toLeftOf="@+id/transpoImage" 
    android:layout_centerVertical="true" 
    android:textSize="12sp" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content"  
    android:clickable = "true" 
    android:textColor="#000000">   
</TextView>  
<ImageButton 
    android:id="@+id/transpoImage" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/pinImage" 
    android:src="@drawable/ic_9_av_make_available_offline" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"/>  
</RelativeLayout> 

我懷疑的TextView是因爲的ImageButton的不可點擊。非常感謝您的幫助。

+0

嘗試添加'機器人:可點擊=「真」'的'TextView'標籤 –

+0

是啊..我想,(它在XML也是)..不起作用。如果我將ImageButton更改爲ImageView,它就可以工作。我沒有明白。 (ImageButton可能會把它搞亂) – Guru

+0

因爲圖像按鈕充當按鈕,而您的文本視圖與佈局相同,所以當您單擊文本視圖時,圖像按鈕單擊事件將始終佔據位置。如果你不使用圖像按鈕點擊事件,然後將其添加到它的佈局 android:clickable =「false」 android:focusable =「false」 –

回答

2

好吧,我想通了自己..反正這裏是萬一別人的答案碰到同樣的問題:

添加此屬性爲您的ImageButton

android:focusableInTouchMode="false" 

還添加

android:descendantFocusability="blocksDescendants" 

爲您的父母佈局

這工作對我來說

+0

也爲我工作 –

0

在你的類中使用一個OnClickListener並將它連接到你的TextView。

0

使用android:clickable="true",在這部分代碼:

<ImageButton 
android:id="@+id/transpoImage" 
android:layout_alignParentRight="true" 
android:layout_alignTop="@+id/pinImage" 
android:src="@drawable/ic_9_av_make_available_offline" 
android:layout_width="wrap_content" 
android:layout_height="match_parent"/>