TAILIEUCHUNG - Android (phần 12)

Building Rich User Interfaces ❘ 517 Introducing the Surface View Under normal circumstances, your applications’ Views are all drawn on the same GUI thread. This main application thread is also used for all user interaction (such as button clicks or text entry). In Chapter 9, you learned how to move blocking processes onto background threads. Unfortunately, you can’t do this with the onDraw method of a View, as modifying a GUI element from a background thread is explicitly disallowed. When you need to update the View’s UI rapidly, or the rendering code blocks the GUI thread for too long, the SurfaceView class is. | Building Rich User Interfaces 517 Introducing the Surface View Under normal circumstances your applications Views are all drawn on the same GUI thread. This main application thread is also used for all user interaction such as button clicks or text entry . In Chapter 9 you learned how to move blocking processes onto background threads. Unfortunately you can t do this with the onDraw method of a View as modifying a GUI element from a background thread is explicitly disallowed. When you need to update the View s UI rapidly or the rendering code blocks the GUI thread for too long the SurfaceView class is the answer. A Surface View wraps a Surface object rather than a Canvas. This is important because Surfaces can be drawn on from background threads. This is particularly useful for resource-intensive operations or where rapid updates or high frame rates are required such as when using 3D graphics creating games or previewing the camera in real time as shown in Chapter 11 . The ability to draw independently of the GUI thread comes at the price of additional memory consumption so while it s a useful sometimes necessary way to create custom Views Surface Views should be used with caution. When Should You Use a Surface View A Surface View can be used in exactly the same way as any View-derived class. You can apply animations and place them in layouts as you would any other View. The Surface encapsulated by the Surface View supports drawing using most of the standard Canvas methods described previously in this chapter and also supports the full OpenGL ES library. Using OpenGL you can draw any supported 2D or 3D object onto the Surface relying on hardware acceleration where available to significantly improve performance compared to simulating the same effects on a 2D canvas. Surface Views are particularly useful for displaying dynamic 3D images such as those featured in interactive games that provide immersive experiences. They re also the best choice for displaying realtime

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.