Android RelativeLayout的父视图不';抓不住滚动手势
我有一些视图层次结构Android RelativeLayout的父视图不';抓不住滚动手势,android,android-relativelayout,Android,Android Relativelayout,我有一些视图层次结构 <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 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>
其中,mGestureDetector是SimpleGetStureDetector的对象
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;
}
};
我有个问题。。
仅当起始点位于BASearchView
内部,而不是在BalanceView
中时,才会调用onScroll
(来自手势检测器)。。为什么?我不明白:(Hm.)。。
我找到了一个丑陋的解决办法。。
简单,我为BalanceView
添加了空的onClickListener
,它开始工作了
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...
}
有人能解释一下吗?)
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...
}