2013-10-18 73 views
0

这是我的XML布局 - 它是一个信息窗口。 我希望当用户点击@ + id/fragment_info_relativelayout_content布局 - 信息窗口将被关闭。Android RelativeLayout onclicklistener未被触发

这是我的XML:

<RelativeLayout 
    android:id="@+id/fragment_info_relativelayout_content" 
    android:layout_width="fill_parent" 
    android:layout_height="70dp" 
    android:background="@drawable/background_info_window" 
    android:clickable="true" > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true" 
     android:layout_margin="5dp" > 

     <!-- The info textView --> 

     <com.coapps.pico.NillanTextView 
      android:id="@+id/fragment_info_textview_info" 
      style="@style/text_shadow_black" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_margin="5dp" 
      android:gravity="center" 
      android:text="Some Text " 
      android:textColor="@android:color/white" 
      app:isBold="true" /> 
    </ScrollView> 
    <!-- Tap to close --> 

    <com.coapps.pico.NillanTextView 
     android:id="@+id/fragment_info_textview_tap_to_close" 
     style="@style/text_shadow_black" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:gravity="right" 
     android:paddingRight="5dp" 
     android:text="@string/button_tap_to_close" 
     android:textColor="@android:color/white" 
     app:isBold="true" /> 
</RelativeLayout> 

这是我的代码:

public InfoWindow(ViewGroup rootView) 
{ 
    this.container = rootView; 
    infoWindowView = LayoutInflater.from(rootView.getContext()).inflate(INFO_WINDOW_LAYOUT_ID, null); 
    //find info window's view 
    contentLayout = infoWindowView.findViewById(R.id.fragment_info_relativelayout_content); 
    contentLayout.setClickable(true); 
    contentLayout.setOnClickListener(this);  
} 

@Override 
public void onClick(View v) { 
      //close the info window 
    close();   
} 

我的问题是,OnClick方法不被解雇每次点击布局... 这是奇怪的,因为它点击一些点击后点击,或点击在右下角的文本...

任何想法??

回答

0

我的建议是,RelativeLayout中的ScrollView处理所有触摸事件,并且不要让RelativeLayout处理任何触摸事件。

在这种情况下,你应该扩展ScrollView,使onTouchEvent回报false

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    super.onTouchEvent(ev); 
    return false; 
} 

而同样以onInterceptTouchEvent

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    super.onInterceptTouchEvent(ev); 
    return false; 
} 

只是尝试一下,告诉我你得到了什么=)