android-如何将触摸侦听器添加到表面视图?

我是Android的新手,所以请原谅!

我正在玩一些相机代码(可在网上找到),并且想在屏幕上显示/隐藏一些按钮.当用户触摸屏幕时,我希望它捕获图像.

我的设置:

1.
主要活动:

public class CameraDemo extends Activity {
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_inuse);

        preview = new Preview(this);

        ((FrameLayout) findViewById(R.id.preview)).addView(preview);

... ...  
// rest of the code that captures the image when a button is pressed.
// the button is defined in main.xml with button id ButtonClicked
}

2.
预览类如下所示:

class Preview extends SurfaceView implements SurfaceHolder.Callback {

    SurfaceHolder mHolder;
    public Camera camera;

    Preview(Context context) {
        super(context);

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

我的问题是

>如何添加触摸功能,以便用户可以触摸预览(比如说一秒钟,或者只是快速触摸),然后会发生什么? (说的图像已保存)
>例如,一个按钮会出现在表面上,例如“下一步”按钮?

解决方法:

@Override
public boolean onTouchEvent(MotionEvent event) {
    return super.onTouchEvent(event);
}

在您的预览类中,MotionEvent对象将告诉您它的触摸方式(以及位置等),并让您执行您想做的任何事情.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...