surfaceview

Divide the screen into SurfaceView and xml layout

落花浮王杯 提交于 2020-01-13 09:42:30
问题 MyActivity has setContentView(MySurfaceView) that covers all the screen. I would like to divide the screen into two parts: the first 2/3 of the screen must be occupied by MySurfaceView and the last 1/3 by my_activity_layout.xml . How can I do that? Thanks. EDIT Thanks for your answers, but I don't have how to apply them in my case. To be clear, these are my objects: 回答1: Solution: To attach an xml file in your layout, you can make use of the <include> tag. Reusing layouts is particularly

SurfaceView相互叠加的坑

我的梦境 提交于 2020-01-12 07:25:35
SurfaceView相互叠加的坑 SurfaceView相互叠加的坑 SurfaceView相互叠加的坑 我们知道可以通过如下代码设置SurfaceView的层级 surfaceView . setZOrderOnTop ( isOnTop ) surfaceView . setZOrderMediaOverlay ( isOnTop ) 但是在实际使用过程中经常发现没有效果,通过查看官方文档得知,要使这两句代码生效 必须在surfaceView的window attach windowManger之前设置才会生效。 所以当你需要更换两个已经显示在屏幕的surfaceview的层级,可以通过如下方式, 第一步:从布局中得到surfaceView 第二步:先移除掉surfaceView 第三步:设置层级 第四步:再重新添加到布局中去 surfaceView = viewGroup . getChildAt ( 0 ) viewGrouP ? . removeAllViews ( ) surfaceView ? . setZOrderOnTop ( isOnTop ) surfaceView ? . setZOrderMediaOverlay ( isOnTop ) viewGroup . addView ( surfaceView ) 来源: CSDN 作者: Jesse_liao

OnDraw() is not fired, nothing is drawn in surfaceView - Android

只愿长相守 提交于 2020-01-11 06:20:13
问题 HI! I have a surfaceView inside a horizontal scrollview that I want to fill with images with a onDraw() call. However, nothing is drawn. I have a class in which the drawing is done from the thread CanvasThread. public class PanelChart extends SurfaceView implements SurfaceHolder.Callback { private CanvasThread canvasthread ; public PanelChart(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub getHolder().addCallback(this); canvasthread = new

SurfaceView和View的最本质的区别

ぐ巨炮叔叔 提交于 2020-01-10 17:39:39
SurfaceView和View的最本质的区别 SurfaceView是在一个新起的单独线程中可以重新绘制画面,而view必须在UI的主线程中更新画面。 在UI的主线程中更新画面可能会引发问题,比如你更新的时间过长,那么你的主UI线程就会被你正在画的函数阻塞。那么将无法响应按键、触屏等消息。当使用SurfaceView由于是在新的线程中更新画面所以不会阻塞你的UI主线程。但这也带来了另外一个问题,就是事件同步。比如你触屏了一下,你需要SurfaceView中thread处理,一般就需要有一个event queue的设计来保存touchevent,这会稍稍复杂一点,因为涉及到线程安全。 常用的设计模式 单例,适配器,策略模式等常用的设计模式需要掌握 单例 public class Singleton{ private volatile static Singleton mSingleton; private Singleton(){ } public static Singleton getInstance(){ if(mSingleton == null){\\A synchronized(Singleton.class){\\C if(mSingleton == null) mSingleton = new Singleton();\\B } } return

android camera介绍

萝らか妹 提交于 2020-01-10 13:59:23
Android 中自定义照相机Camera详解 要想定义一个照相机需要用到两个核心类:Camera和SurfaceView Camera类一些API Camera用于管理和操作camera资源,他提供了完整的相机底层接口。可以通过camera.getParameters()来获取Camera的参数用以设置照片的预览尺寸、拍摄尺寸、预览帧、拍摄帧、设置光圈、曝光、聚焦、颜色特效等。 SurfaceView类 用于绘制相机的预览功能的类,提供给用户的实时预览的图像。普通的view以及派生类都是共享同一个surface的,所有的绘制都是在UI线程之中绘制的。而surfaceview是一种比较特殊的view,他并不与其他的普通的view共享surface,而是在内部持有了一个独立的surface,surfaceview负责管理这个surface的格式,尺寸及显示位置。由于UI线程还要和其他的线程交互逻辑,因此对view的更新速度和帧率无法保证,而surfaceview由于持有一个独立的surface,因而可以在独立的线程中进行绘制,提供更高的帧率。自定义相机的预览图像由于对更新速度和帧率要求比较高,所以比较实用surfaceview来显示。 SurfaceHolder surfaceholder是控制surface的一个抽象接口,他能够控制surface的尺寸和格式

Set the Background Image of a SurfaceView

余生长醉 提交于 2020-01-09 10:12:26
问题 Is there a way to set the background image of a SurfaceView? Does it have to be done in xml or can I do it all in Java - I've got something that looks like this in my constructor: Drawable sky = (getResources().getDrawable(R.drawable.sky)); this.setBackgroundDrawable(sky); But it still doesn't show anything. 回答1: You cannot set a background drawable on a SurfaceView. You'll have to draw the background onto the surface yourself. 回答2: While you can't directly set a background image to a

Set the Background Image of a SurfaceView

和自甴很熟 提交于 2020-01-09 10:12:05
问题 Is there a way to set the background image of a SurfaceView? Does it have to be done in xml or can I do it all in Java - I've got something that looks like this in my constructor: Drawable sky = (getResources().getDrawable(R.drawable.sky)); this.setBackgroundDrawable(sky); But it still doesn't show anything. 回答1: You cannot set a background drawable on a SurfaceView. You'll have to draw the background onto the surface yourself. 回答2: While you can't directly set a background image to a

Annoying lags/stutters in an android game

喜你入骨 提交于 2020-01-09 05:00:06
问题 I just started with game development in android, and I'm working on a super simple game. The game is basically like flappy bird. I managed to get everything to work, but I get a lot of stutters and lags. The phone I'm using for testing is LG G2, so it should and does run games much heavier and complex than this. Basically there are 4 'obstacles' that are a full screen width apart from each other. When the game starts, the obstacles start to move (toward the character) at a constant speed. The

Camera实现预览、拍照

随声附和 提交于 2020-01-08 23:41:12
1.利用Intent方法实现拍照并保存 在菜单或按钮的选择操作中调用如下代码,开启系统自带Camera APP,并传递一个拍照存储的路径给系统应用程序,具体如下: imgPath = "/sdcard/test/img.jpg"; //必须确保文件夹路径存在,否则拍照后无法完成回调 File vFile = new File(imgPath); if(!vFile.exists()) { File vDirPath = vFile.getParentFile(); //new File(vFile.getParent()); vDirPath.mkdirs(); } Uri uri = Uri.fromFile(vFile); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);// startActivityForResult(intent, SystemCapture); 上面我们使用的是startActivityForResult,所以最好需要重载void onActivityResult(int requestCode, int resultCode, Intent data)函数,不过因为当传入文件路径的的情况下

Android Camera后台拍照

喜夏-厌秋 提交于 2020-01-08 08:00:48
http://item.congci.com/item/android-camera-houtai-paizhao 有许多人希望在不让用户知道的情况下,使用Android后台Service调用摄像头拍照,网上不少资料,都讲到不预览无法实现拍照,涉及到用户隐私,属于非法调用摄像头...怎么办!!! 曾经看到一篇博文,里面有一句经典的话:没有什么是绝对的,没有什么是绕不过去的。接下来就来分析一下怎么绕过去,实现不预览拍照。 要求①:不让用户看到拍照界面 难点:预览界面必须在一个Activity上,而弹出了Activity之后,用户再傻,都知道你在干嘛,怎么办!! 思路:弹出Activity就弹出吧,咱对Activity做手脚,让他全透明,再来个全屏,和无标题栏,不就和没东西弹出来一个效果。 要点②:不预览 难点:非法调用摄像头,怎么办!!报错 "take picture failed ! !" 思路:你要在Activity上有SurfaceView进行预览,那就来一个SurfaceView,打不了咱再对SurfaceView做手脚就是 了...设这SurfaceView长和宽都为0.1 你不是要预览吗,也有,问题是预览框这么小,要是你还能看到那就没办 法了... 好了,不多说,思路有了就开始工作: 首先,用来拍照的Activity布局: < RelativeLayout xmlns