1. the OOM error occurs when an image is displayed every MS in imageview. solution:
Bitmapdrawable = (bitmapdrawable) image. getdrawable ();
// If the image has not been recycled, forcibly recycle the image first.
If (bitmapdrawable! = NULL &&! Bitmapdrawable. getbitmap (). isrecycled ()){
Bitmapdrawable. getbitmap (). Recycle ();
}
Image. setimagebitmap (bitmapfactory. decodestream (assetfile ));
2. The file name in the assets folder cannot contain Chinese characters.
Android is based on the Linux system. Linux allows other symbols except the above symbol in the file name, but it is not recommended that you do so. If the file name in Windows contains Chinese characters, copy the file to the assets folder of the android project. If you run this android project, an error is returned. If you delete the special characters in the file name, the error is OK.
3. When customizing the view component, if you override the ontouchevent method, do not return Super. ontouchevent (event), it should be changed to return true because:
(1) The ontouchevent (event) method of the parent class may not be processed, but false is returned.
(2) If false is returned, the motionevent. action_move and motionevent. action_up events will no longer be received in this method.
4. About suifaceview plotting: access to the underlying surface is provided via the surfaceholder interface, which can be retrieved by callingGetholder ()
. Use the getholder () method to obtain the surfaceholder interface: surfaceholder = getholder ();
How to draw surfaceview images?
(1) Lock canvas
// Obtain the canvas instance
Canvas canvas = surfaceholder. lockcanvas ();
(2) perform corresponding drawing operations
Canvas. drawcircle (float CX, float cy, float radius, paint );
(3) unlock the canvas and submit the painted canvas, that is, re-draw the canvas.
Surfaceholder. unlockcanvasandpost (canvas );
Difference between view and surfaceview
1. surfaceview is a subclass of view.
2. The view does not have a cache mechanism and can only be updated throughout the view. surfaceview has a dual-buffer mechanism that allows partial update;
3. surfaceview can be re-painted in a new separate thread, and view must be updated in the main thread of the UI.
If the update frequency is frequent, surfaceview is used; otherwise, view is used.
If you have any omissions, please correct them.