Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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 onTouchEvent的Force RelativeLayout焦点_Android_Touch_Android Relativelayout - Fatal编程技术网

Android onTouchEvent的Force RelativeLayout焦点

Android onTouchEvent的Force RelativeLayout焦点,android,touch,android-relativelayout,Android,Touch,Android Relativelayout,我正在开发我的第一个游戏。机制很简单:在屏幕上随机移动的泡泡。我的画布是相对活跃的。布局很简单 <RelativeLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/header" /> 问题是,有时触摸事件不会发生。我想知道是否有某种机制可以始

我正在开发我的第一个游戏。机制很简单:在屏幕上随机移动的泡泡。我的画布是相对活跃的。布局很简单

<RelativeLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/header" />
问题是,有时触摸事件不会发生。我想知道是否有某种机制可以始终抓住焦点,确保我的相对物中的触摸事件


如果您想捕获所有
RelativeLayout
TouchEvent
事件,欢迎提供任何帮助,然后实现自定义视图扩展
RelativeLayout
并在
onInterceptTouchEvent()中处理事件

例如:

public class RelativeLayoutExt extends RelativeLayout {
    public RelativeLayoutExt(Context context) {
        super(context);
    }

    public RelativeLayoutExt(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RelativeLayoutExt(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public RelativeLayoutExt(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // TODO handle your touches here
        return super.onInterceptTouchEvent(ev);
    }
}
public class RelativeLayoutExt extends RelativeLayout {
    public RelativeLayoutExt(Context context) {
        super(context);
    }

    public RelativeLayoutExt(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RelativeLayoutExt(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public RelativeLayoutExt(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // TODO handle your touches here
        return super.onInterceptTouchEvent(ev);
    }
}