顶部翻译:
/**
* <p>TextureView 可用于显示内容流。例如,这样的内容流可以是视频或 OpenGL 场景。
* 内容流可以来自应用程序的进程以及远程进程.</p>
*
* <p>TextureView 只能在硬件加速窗口中使用。在软件中渲染时,TextureView 不会绘制任何内容</p>
*
* 和 SurfaceView 不同, TextureView 不会创建一个单独的窗口,而是像一个普通的 View
* 这个关键区别允许 TextureView 被移动、变换、动画等。
* 例如,您可以通过调用使 TextureView 半透明: myView.setAlpha(0.5f)
*
* 使用 TextureView 很简单:你需要做的就是获取它的 SurfaceTexture
* 然后可以使用 SurfaceTexture 来渲染内容
* 以下示例演示了如何将相机预览渲染到 TextureView 中:
*
* <pre>
* public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
* private Camera mCamera;
* private TextureView mTextureView;
*
* protected void onCreate(Bundle savedInstanceState) {
* super.onCreate(savedInstanceState);
*
* mTextureView = new TextureView(this);
* mTextureView.setSurfaceTextureListener(this);
*
* setContentView(mTextureView);
* }
*
* public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
* mCamera = Camera.open();
*
* try {
* mCamera.setPreviewTexture(surface);
* mCamera.startPreview();
* } catch (IOException ioe) {
* // Something bad happened
* }
* }
*
* public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
* // Ignored, Camera does all the work for us
* }
*
* public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
* mCamera.stopPreview();
* mCamera.release();
* return true;
* }
*
* public void onSurfaceTextureUpdated(SurfaceTexture surface) {
* // Invoked every time there's a new Camera preview frame
* }
* }
* </pre>
*
* <p>可以通过调用 getSurfaceTexture() 或使用 TextureView.SurfaceTextureListener 来获得 TextureView 的 SurfaceTexture
* 重要的是要知道 SurfaceTexture 只有在 TextureView 附加到窗口后才可用(并且 onAttachedToWindow() 已被调用。)
* 因此,强烈建议您使用侦听器在 SurfaceTexture 可用时收到通知</p>
*
* <p>需要注意的是,只有一个生产者可以使用 TextureView。
* 例如,如果您使用 TextureView 显示相机预览,则不能同时使用 lockCanvas() 绘制到 TextureView</p>
*
*/