2013-09-21 38 views
1

我有一個可點擊的Relativelayout。我有一個內部元素(一個ImageButton),我也想點擊。實現父母和子女的可點擊視圖

佈局是可點擊的,直到我加入ImageButton;現在只有這是可點擊的。

我已經在兩個元件(我只在xml佈局試過)嘗試的focusablefocusableInTouchMode = truefalse所有組合。我怎樣才能讓它們都是可點擊的?

我的代碼;注意這是在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> 

回答

0

利用你的父母

android:addStatesFromChildren="true" 

如果用這種那麼就不要使用,否則下面你會得到卡住溢出異常

怎麼樣設置這個給你的孩子

android:duplicateParentState="true" 
+0

我厭倦了這一點,它不工作;儘管我已經在父母和孩子中刪除了所有「focusable」的實例。我會在問題中添加更多代碼。 – KickingLettuce

+0

@KickingLettuce你想爲相對佈局和按鈕或只有一個事件生成單擊事件 – Trikaldarshi

+0

只使用這個'android:duplicateParentState =「true」'使得兩個項目現在不可點擊。 – KickingLettuce

0

設置android:descendantsFocusability =「blockDescendants」上的 RelativeLayout