What problems are often encountered in Android development

Source: Internet
Author: User

Android Development Issue Highlights


Issue One: No marked region found along edge error

A: If you use the nine patch resource in an Android project, you might have a error:9-patch image eoeandroid. 9.png Malformed. Or No marked region found along edge . and Found along top edge. The error is mainly because the picture does not have pixels positioned around it.


Question two: What is the role of layout_weight?

A: Many times you may find that there is a layout_weight attribute in the layout XML file, not layout_height or layout_width, so what is Layout_weight? It's defined as a specific weight. For example, in a linearlayout, there are three TextView controls, if the first setting Layout_height is 1, the second is 1, and the last is 2, the size of these three TextView controls is 1:1:2. In Android development we may often use this property to arrange some controls.


Problem three: Android Zip decompression class processing Chinese name garbled

A: At present, the underlying library on the Android platform still has a lot of imperfect places, such as the Zlib library processing Zip files can not do the correct processing of Chinese filenames, and can not be similar to the J2SE Android.util.zip class does not have setencoding method processing. The solution is to introduce the Apache Ant Library for decompression, and the Apache Ant Library contains a complete XML DOM4J parsing library for document preservation.

Of course, the problem of the introduction of Apache Ant Library is caused by the program after compiling the volume becomes bloated, the algorithm because the Java write efficiency will be greatly reduced, but solve the problem is still possible, heavyweight processing or put on the server is better.

At present, the Android platform underlying library in many places do not neighbor Ruyi, many key places have problems.


Question four: Layout_toright Error resolution method

A: A friend asked to import some old version of the Android project, there was a layout_toright error, specific as no resource identifier found for attribute ' layout_toright ' in The package ' Android ', in fact, in the Android 1.1 started the SDK to make a small change, such as Android:id to Android:name, here Layout_toright replaced Layout_torightof can. In some cases ADT may also help us fix the problem, Tony tip right-click directly in the wrong place and choose quick fix to see.


Question five: What does the synchronized in the Android method mean?

A: Many friends may see synchronized words in some of the Android methods, such as public static synchronized string gethttpresponse (string url), In fact, this problem belongs to the Java Foundation and Android-Independent, using the keyword synchronized literal means of synchronization, and in practice in the multithreaded program

To prevent an unexpected result (what would happen?) Tony, for example, a thread is writing a file, has not finished writing, but another thread began to read it, adding synchronized can lock the method, that is, only one thread alone access to the method, similar to Win32 in the critical section critical sections is a reason. However, to suggest that the method should not be abused, the use of thread-safe situations will increase the system overhead impact performance. And sometimes in the method will appear synchronized (this), good synchronized (this) is generally used to lock the content of a loop, also in the iphone cocoa is applicable.


Problem Six: ListView does not display properly in ScrollView

A: When the ListView is placed in the ScrollView, there are still some bugs in the Android platform, the status is that the ListView is only about a half a line (the total item must be greater than 2 rows, such as 10 rows), and the layout property settings are still not fixed. By analyzing the ListView and ScrollView constructs did not find a good solution, now can be implemented by their own ListView to solve, Tony solves the way is to rewrite the ListView onmeasure to recalculate the number of rows displayed. Hopefully after the Android version, at least 2.1 will be able to improve later.


Question seven: The content of the adapter has changed solution

A: Many novices may not be very clear about the thread and message as well as the handler, Looper concepts in Android development, and may produce something like the content of the adapter have changed but a ListView did Not receive a notification make sure the content of your adapter are not modified from a background thread. But only the error from the UI thread. From this problem in the mailbox, the workaround must have detailed code, but the following points can help you understand the problem:

1. Try adapter's notifydatasetchanged () method, of course, mainly look at your code details.


2. Change the adapter adapter content when not in the background thread, must be processed in the UI thread, this can be resolved by handler outgoing.


Issue eight: The role of notifydatasetchanged in adapter

A: For Android development to deal with some interface needs to deal with the adapter adapter, although Android comes with some such as arrayadapter but most of the circumstances do not meet our needs, So it is necessary to derive a class from Baseadapter to meet our special needs.

First, we might rewrite GetView (), map a custom layout XML load or create it from Xxxview by Layoutinflater's Inflate method. These people may memorized but still many Android developers are not very understanding of the notifydatasetchanged () method in Baseadapter, The Notifydatasetchanged method controls how the contents of each item are refreshed by forcing calls to GetView if the contents of the adapter are changed by an external method.


Issue nine: Resource is out of sync with error

A: Many netizens complain that Android eclipse is poor, often a bunch of inexplicable errors, Resource is out of sync with the file system error how to solve it? This is mainly because the resource file is opened by the editor outside of Eclipse, in order to ensure that the things just saved from the conflict, the IDE itself to protect, the most stupid way to solve is to turn off eclipse to open, prompted to save the resource click No, or directly press the F5 key, If the program is automatically compiled when the empty project is regenerated. Indeed, carbide C + + (Eclipse-based) has never been efficient for developers since the Symbian era years ago, compared to the development of the iphone's Xcode or Windows Mobile's visual In studio, the eclipse is not a compliment to Java development, and the fake animation and bad user experience are unforgettable.


The article is organized from Changsha software training http://www.cshope.net/


This article is from the "Emperor Niang blog" blog, please be sure to keep this source http://8878509.blog.51cto.com/8868509/1408402

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.