2012-01-02 58 views
0

我有一個相對的佈局組成的幾個自定義視圖,當我點擊其中一個視圖說「NavigationSelector」另一個視圖說「AssistanceSelector」必須修改。我已經爲NavigationSelector的對象添加了setOnClickListener事件,但我發現在任何地方點擊了NavigationClickListener所調用的整個相對佈局。setOnClickListener只有一個包含許多其他視圖的相對佈局的視圖

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

    <com.dashboard.customviews.NavigationSelector 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:id="@+id/navigationSelector"> 
    </com.dashboard.customviews.NavigationSelector> 

    <com.dashboard.customviews.AssistanceSelector 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:id="@+id/assistanceSelector"> 
    </com.dashboard.customviews.AssistanceSelector> 

Activity.java: 

    NavigationSelector objNavigationSelector=null; 
    objNavigationSelector=(NavigationSelector)findViewById(R.id.navigationSelector); 
    objNavigationSelector.setOnClickListener(new NavigationClickListener(this)); 

class NavigationClickListener implements OnClickListener 

public void onClick(View v) { 

     switch (v.getId()) { 
     case R.id.navigationSelector: //do required stuff 
      break; 
     ... 
     } 

回答

0

添加標籤android:clickable="false"到您不希望被點擊的佈局項目。

希望它有幫助!

+0

恐怕它不起作用。我將android:clickable =「false」設置爲相對佈局中的所有其他項目,但點擊仍在被識別。 – rosemary 2012-01-03 09:14:37

0

我認爲這是因爲你的兩個觀點共享相同的位置。修復你的佈局參數,都有android:layout_alignParentLeft="true"

+0

否在自定義視圖中,我已將一個對象放在另一個對象的上方 – rosemary 2012-01-03 09:16:16

+0

NavigationSelector cutomview: int canvasHeight = canvas.getHeight(); int centreX = 10; int NaviSelectorHeight = NaviSelector.getHeight(); int NaviSelectorcentreY =(canvasHeight - NaviSelectorHeight)/ 2-40; canvas.drawBitmap(NaviSelector,centreX,NaviSelectorcentreY,SelectorPaint); AssistanceSelect cutomview: int centreX = 10; int AssistSelectorHeight = AssistSelector.getHeight(); int AssistSelectorcentreY =(canvasHeight - AssistSelectorHeight)/ 2; canvas.drawBitmap(AssistSelector,centreX,AssistSelectorcentreY,SelectorPaint); – rosemary 2012-01-03 09:22:17

相關問題