我是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
}
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,
如何添加触摸功能以便用户可以触摸预览(比如一秒钟,或者只是快速触摸)并且会发生什么?(说保存图像)
例如,表面上会出现一个按钮,上面写着"下一步"按钮吗?
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
在您的预览类中,MotionEvent对象将告诉您它是什么样的触摸(和位置等)并让您做任何您想做的事情.
| 归档时间: |
|
| 查看次数: |
12828 次 |
| 最近记录: |