Minor issues in Android Development

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.