Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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:触摸事件不工作_Android_Touch - Fatal编程技术网

Android:触摸事件不工作

Android:触摸事件不工作,android,touch,Android,Touch,这是我的主要活动代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Display display = getWindowManager().getDefaultDisplay(); //Setting the FileBrowser FrameLayout

这是我的主要活动代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Display display = getWindowManager().getDefaultDisplay();        

    //Setting the FileBrowser FrameLayout Settings.
    FrameLayout fileBrowserLayout =  (FrameLayout) findViewById(R.id.flFBrowser);
    FrameLayout previewLayout = (FrameLayout) findViewById(R.id.flPreview);
    TextView instructions = (TextView)findViewById(R.id.tvInstructions);

    fileBrowserLayout.getLayoutParams().width = display.getWidth()*WidthFileBrowser/100;
    previewLayout.getLayoutParams().width = display.getWidth()*WidthPreview/100;
    previewLayout.getLayoutParams().height = display.getHeight()*PreviewHeight/100;
    instructions.getLayoutParams().width = display.getWidth()*WidthPreview/100;
    instructions.getLayoutParams().height = display.getHeight()*InstructionsHeight/100;
    instructions.setText(Instructions);
    instructions.setTextSize(InstructionTextSize);
    instructions.setTextColor(InstructionTextColor);
    instructions.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
    instructions.setGravity(Gravity.CENTER_HORIZONTAL);

    //Attempting to set the Fragment        
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();       
    FileBrowser fb = new FileBrowser();
    preview = new Preview();
    ft.add(R.id.flFBrowser,fb);
    ft.add(R.id.flPreview, preview);
    ft.commit();

}
这是我的预览片段代码

public class Preview extends Fragment implements ViewFactory,OnTouchListener{

@Override
public boolean onTouch(View v, MotionEvent event) {
    System.err.println("Something touched me!");
    return true;
}
}
onActivityStarted上有更多初始化代码,但它与初始化imageswitcher有关

但是我不明白为什么我的触摸事件没有注册


有人能帮我吗?

问题是,你没有在你的
预览
类中实现的
上注册你的
。我不知道也不认为(基于API)可以为片段注册一个触摸监听器,但可以为任何视图注册

尝试为一个框架布局注册onTouchListener。您可以在初始化预览对象后执行此操作:

preview = new Preview();
previewLayout.setOnTouchListener(preview);

就我而言,我的孩子们正在拦截触摸事件。我想将识别器附加到父布局,因此为此,我需要截获触摸事件()。我必须对布局进行子类化,并覆盖
onInterceptTouchEvent()
,以便将事件传递给可能附加到布局的任何触摸侦听器。我在一个片段中实现了我的监听器和检测器,监听器将事件转发给检测器。

Try
Log.e(“main”,“something moved me!aiiee!”)