我有一些视图层次结构
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TOP_VIEW_LAYOUT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
</LinearLayout>
<BASearchView
android:id="@+id/SEARCH_FIELD"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</BASearchView>
<BalanceView
android:id="@+id/CARD_INFO_FIELD"
android:layout_width="match_parent"
android:layout_height="44dp"/>
</LinearLayout>
其中public class BASearchView extends LinearLayout
和public class BalanceView extends RelativeLayout
。我还public class TopView extends LinearLayout
使用TOP_VIEW_LAYOUT
..所以,有时间提问。我正在尝试在TopView
类
@Override
public boolean dispatchTouchEvent( MotionEvent event ) {
Log.i( TAG, "dispatchTouchEvent() has been called" );
mGestureDetector.onTouchEvent( event );
return super.dispatchTouchEvent( event );
}
其中mGestureDetector是SimpleGestureDetector的对象
private SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener() {
@Override
public boolean onFling( MotionEvent e1, MotionEvent e2, float vx, float vy ){
Log.i( TAG, "TopView fling has been detected" );
return false;
}
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i( TAG, "TopView scroll has been detected" );
return false;
}
};
我有一个问题..
onScroll
(来自手势检测器)仅在BASearchView
内的起点,而不是BalanceView
内调用。为什么?? !!我无法理解:(
答案 0 :(得分:0)
嗯..
我找到了一个丑陋的解决方案..
很简单我为onClickListener
添加了空BalanceView
,它就变得有效了
public class BalanceView extends RelativeLayout {
public BalanceView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
inflater.inflate( R.layout.balance_view, this, true );
setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
}
});
//some code..
}
//some class code...
}
任何人都可以解释一下吗? )