I've been studying Android especially View system. I have a question differences between them but there is no documents or references in my mother language. So I want to know from you guys.
-
1may be @ChintanRathod link helpful to you.Nice document brother +1 – Zala Janaksinh Jun 04 '13 at 12:47
6 Answers
TextureView
A TextureView can be used to display a content stream. Such a content stream can for instance be a video or an OpenGL scene.
Example :
https://github.com/dalinaum/TextureViewDemo
Document:
http://developer.android.com/reference/android/view/TextureView.html
SurfaceView
Provides a dedicated drawing surface embedded inside of a view hierarchy.
Examples :
http://www.mindfiresolutions.com/Using-Surface-View-for-Android-1659.php
http://blog.wisecells.com/2012/06/04/surface-view-android/
Document:
http://developer.android.com/reference/android/view/SurfaceView.html

- 25,864
- 13
- 83
- 93
SurfaceView
and TextureView
both are inherited from android.view.View class.
However there are some structural difference between them.
When you want more control of the single drawing board, go for SurfaceView
- You cannot overlay two
SurfaceView
.
TextureView
has the following advantages over SurfaceView
:
- You can Animate, Transform and Scale a
TextureView
.

- 306
- 1
- 4
- 12
-
14You can certainly stack two SurfaceViews if you use a FrameLayout and setZOrderMediaOverlay to true on of the surface views – Clocker Feb 15 '17 at 15:23
-
Agree with @Clocker, you can use `setZOrderOnTop`. Maybe you are saying you can't add `SurfaceView` inside `SurfaceView`? – Bitwise DEVS Jul 28 '22 at 18:50
In addition to other answers, this could be beneficial for novice android developers or anyone who will see this.
In my case, using this snippet in OnCreate
method helped me to find out which device can use SurfaceView
if (
GLES20.glGetString(GLES20.GL_RENDERER) == null ||
GLES20.glGetString(GLES20.GL_VENDOR) == null ||
GLES20.glGetString(GLES20.GL_VERSION) == null ||
GLES20.glGetString(GLES20.GL_EXTENSIONS) == null ||
GLES10.glGetString(GLES10.GL_RENDERER) == null ||
GLES10.glGetString(GLES10.GL_VENDOR) == null ||
GLES10.glGetString(GLES10.GL_VERSION) == null ||
GLES10.glGetString(GLES10.GL_EXTENSIONS) == null) {
// try to use SurfaceView
} else {
// try to use TextureView
}
Hope it helps people who develop video player apps :)

- 1,253
- 2
- 22
- 37
When it comes to video playback, SurfaceView
instead of a TextureView
. There are some important differences:
- TextureViews behave like normal views. SurfaceViews don't. A SurfaceView has a transparent "hole" in the UI through which an independent Surface layer can be seen. This Surface is sent directly to the system graphics compositor.
- Because the video is being composited with the UI by the system compositor, rather than the application, it can often be done more efficiently (e.g. using a hardware composer "overlay"). This can lead to significant battery savings when playing a long movie.
- On the other hand, the TextureView contents can be freely scaled and rotated with a simple matrix. The SurfaceView output is limited to scaling, and it's more awkward to do.
- DRM-protected content can't be touched by the app (or even the system compositor). We have to point the MediaCodec decoder at a Surface that is composited by a hardware composer overlay. The only way to do the app side of this is with SurfaceView.
The MediaCodec decoder requests buffers from the Surface, passing the video dimensions in as arguments. The Surface provides buffers with a matching size, which means the video data will completely cover the Surface. As a result, there's no need to use SurfaceHolder#setFixedSize() to set the dimensions. The hardware scaler will scale the video to match the view size, so if we want to preserve the correct aspect ratio we need to adjust the View layout. We can use our custom AspectFrameLayout for this. The actual playback of the video -- sending frames to a Surface -- is the same for TextureView and SurfaceView.
Read through Choosing a surface type section in exoplayer documentation for further.

- 10,213
- 3
- 52
- 73
-
Thank you. This is a highly useful answer for people weighing between SurfaceView and TextureView. – Hong Mar 25 '23 at 19:07
Android SurfaceView vs TextureView
SurfaceView
and TextureView
can be used to from another thread
Surfaceview
- better performance to use in bound with UI elements
- less memory footprint
TextureView
- API 14
- separate window is not created(unlike Surfaceview) that is why alpha, rotation, move, transform, animate are better
- is used inside hardware accelerated mode

- 29,217
- 8
- 193
- 205
A SurfaceView takes the same parameters as other views, but SurfaceView contents are transparent when rendered.
A TextureView has better alpha and rotation handling than a SurfaceView, but a SurfaceView has performance advantages when compositing UI elements layered over videos.
For more : https://source.android.com/devices/graphics/arch-tv

- 884
- 4
- 16
- 25

- 1,387
- 11
- 13