Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RelativeLayout的父视图不';抓不住滚动手势_Android_Android Relativelayout - Fatal编程技术网

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...   
}