Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android view or surfaceView, which should i use?

Ive been trying to make a scrollable/zoomable app and everything has gone great except for drawing bitmaps. It is a very large image (6656 by 4096) that i have split into tiles. There is a rectangle array that the bitmaps are drawn to, and it detects what rectangle is in the top left corner so it can draw the bitmaps that will cover the user's viewable screen. My problem is this all lags when the app has to load the bitmaps into memory; Once they are loaded it isnt an issue. I started with 512 by 512 tiles, then went down to 128 by 128. although it helped, there still is some noticeable lag. I have been looking into surfaceView and wanted your opinions if i should stick with View, or use surfaceView to solve my lag.

like image 833
jfisk Avatar asked Jul 30 '10 02:07

jfisk


People also ask

What is a SurfaceView Android?

Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

What is the difference between SurfaceView and TextureView?

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.

How do I make SurfaceView transparent?

This example demonstrates how to make surfaceview transparent in an Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

If you derive your own SurfaceView you have several advantages.

Mainly because you can have all drawing logic in a seperate thread. This means that the ui won't wait for you (I'm assuming the lag is because the ui-thread is being blocked?).

SurfaceView's are also faster in nature.

I also find this overview on developer.android.com to be a good reference to choose drawing method.

like image 60
monoceres Avatar answered Oct 14 '22 06:10

monoceres