Problems encountered during android development [1]: problems encountered during android Development

Source: Internet
Author: User

Problems encountered during android development [1]: problems encountered during android Development

Problems encountered during android development [1]

I. Can I use the same include multiple times in an xml file?

Http://www.apkbus.com/android-104152-1-1.html

Use of the include tag in android

Http://blog.csdn.net/wangljgood/article/details/6556175

II
Android button is centered at the bottom of linerlayout

Set the weight outside the button to 1.0

3. Button shape
Http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html

4. animation
Http://www.eoeandroid.com/forum.php? Mod = viewthread & tid = 564.
Http://blog.csdn.net/feng88724/article/details/6318430
Http://www.360doc.com/content/13/0102/22/6541311_257754535.shtml
Http://blog.csdn.net/aminfo/article/details/7847761
Http://blog.csdn.net/xsl1990/article/details/19125193
Http://www.cnblogs.com/bavariama/archive/2013/01/29/2881225.html
Http://www.oschina.net/question/97118_34523
Http://www.eoeandroid.com/thread-67329-1-1.html

5. Proportional scaling of imageview
Android: scaleType controls how images are resized/moved to match the size of ImageView.

ImageView. scaleType/android: The difference between scaleType values: CENTER/center is displayed in the CENTER of the original size of the image. When the length/width of the image exceeds the length/width of the View, then, the center part of the captured image is displayed. CENTER_CROP/centerCrop scales up the image size in the center to make the image length (width) equal to or greater than the View length (width) CENTER_INSIDE/centerInside displays the image content in the center, scale down the image size proportionally or make the image length/width equal to or less than the View length/width FIT_CENTER/fitCenter to scale up/down the image to the View width proportionally, in the center, FIT_END/fitEnd is used to increase or decrease the image width proportionally to the View width. in the lower part of the View, FIT_START/fitStart is used to increase or decrease the image width proportionally to the View width, FIT _ XY/fitXY scales up or down the image proportionally to the View size. The MATRIX/matrix is drawn using a MATRIX, and the image is dynamically zoomed in and enlarged for display.

Sat. How does android get the time difference?

7.
ImageLoader must be init with configuration before using error Solution
ImageLoader. init (ImageLoaderConfiguration. createDefault (MainActivity. this ));

8. Java. lang. StackOverflowError
StackOverflow is generally caused by an endless loop or recursive call in your program;

9.
Java. lang. ClassCastException: android. app. Application cannot be cast to MyApplication

The reason for this exception is that the new application class (public class Application extends android. app. application), not in manifest. so the compiler throws an exception: java. lang. classCastException: android. app. application cannot be cast to android_serialport_api.sample.Application

Solution: add the following content to manifest. xml:
[Html] view plaincopy

<application   android:name="xxx.MyApplication">  

Another method is http://blog.csdn.net/leon90dm/article/details/8521939.

13. Modify and set the length of Ctrl + Shift + F in eclipse.

In the Preferences of window, Java-> Code Style-> Formatter finds the formatting template of Ctrl + Shift + F, which cannot be directly modified here. Because it is the default eclipse template, it is read-only. We can create a new Formatter and click edit to modify the template. I modified the template mainly by changing the Ctrl + Shift + F and changing my code to multiple lines. Modify the Line Wrapping tab in the tab. There is a Maximum line with: 80 (default). The default value is 80. We can change it to 120, in this way, a line break will not exceed 120 characters! You can modify other formats as needed. Of course, you can also export your custom format, which is in xml format. It can be imported elsewhere. In this way, no more customization is required.

15. fragment Andriod development skills -- Fragment lazy loading

In an Activity, viewpager (or other containers) and multiple Fragment may be used in combination. If each fragment needs to load data, load data locally, or load data from the network, when this activity is created, a large amount of resources need to be initialized. Of course we are not satisfied with this result. So, can we initialize it only when switching to this fragment? The answer is http://blog.csdn.net/maosidiaoxian/article/details/38300627 in the setUserVisibleHint method in Fragment.

16. Do not instantiate multiple Fragment Switches
Http://www.yrom.net/blog/2013/03/10/fragment-switch-not-restart/

18. Do not format comments in Eclipse settings
Eclipse settings do not format comments
The vertices in the annotations contain formatted text, and the format is messy. The solution is as follows:
Windows> Preferces> java> Code Style> Formatter> Edit> Comments
Deselect Enable Javadoc comment formatting ".

19. android-Ultra-Pull-To-Refresh

20. Linux dynamic gif image recording

Install byzanz and install sudo add-apt-repository ppa in Ubuntu: fossfreedom/byzanzsudo apt-get update sudo apt-get install byzanz. You can use the following command to complete the recording process: byzanz-record-d 40-x 0-y 0-w 400-h 320 byzanz-demo.gif where: -d 40 indicates the recording duration of 40 seconds-x 0 x y 0 y 0 y 0 y) -w 400 recording area width-h 320 recording height byzanz-demo.gif detailed file name parameters can be viewed through byzanz-record -- help. Http://www.tuicool.com/articles/yfjrem::gif

23. public void onPageScrollStateChanged (int arg0)

This method is called when the status changes. The arg0 parameter has three States (, 2 ). Arg0 = 1 of the hour is sliding, arg0 = 2 of the hour of the implied sliding is completed, arg0 = 0 of the hour of the implied nothing. When the page starts to slide, the order of the three States is)

24.
Add-Dorg. eclipse. swt. browser. DefaultType = mozilla to the eclipse. ini file.
Then run the clean command.

25. Open-source framework
Http://blog.csdn.net/jonemill/article/details/42149783

26. viewpager implements the Gallery (multiple Fragment on one screen) Effect

27. svn command
$ Svn add *-force
Http://developer.51cto.com/art/201005/201633.htm

28. Array constants can only be used in initializers
Int CC [] = {1, 2, 3}; when the array is defined and the initial value is attached, the length of the array is determined, and the length is 3
In addition, the array can no longer be assigned a new value as defined in
You must change it one by one.
CC [0] = 1;
CC [1] = 2;
CC [2] = 3;
Array constants can only be used in initializers

29. android plug-in

30. scrollview can also be rolled when the content is small
Add the attribute android: overScrollMode = "always" to ScrollView in XML.

31. The default android background is yellow when the gridview/listview is clicked. How can I remove the selected yellow background?

Method 1: Set the gridView when the control is initialized. setSelector (new ColorDrawable (Color. TRANSPARENT); listView. setSelector (new ColorDrawable (Color. TRANSPARENT); Method 2: Set the listSelector attribute in the layout file <GridView android: listSelector = "@ android: color/transparent" android: numColumns = "auto_fit" android: columnWidth = "50dp" android: stretchMode = "spacingWidth" android: layout_weight = "1.0" android: layout_height = "0dip" android: layout_width = "match_pare Nt "/> <ListView android: listSelector =" @ android: color/transparent "android: layout_height =" match_parent "android: layout_width = "match_parent"/> You can also customize the desired effect. Recommended Method 2: decouple logical code and layout files.

In addition, listview has two basic problems.
Question 1:

When the listview is dragged, the background image disappears into a black background. After the drag is completed, our own background image will be displayed. Solution: android: scrollingCache = "false" or android: cacheColorHint = "#00000000": setScrollingCacheEnabled (false), setCacheColorHint (0), or setCacheColorHint (Color. TRANSPARENT); Question 2: the top and bottom of the listview have a black shadow. Solution: in xml: android: fadingEdge = "none" code: setFadingEdgeLength (0 );

32. ScrollView only supports one subitem. The error "ScrollView can host only one direct child" is returned.
Solution:

In ScrollView, set LinearLayout as a subitem and add other views to LinearLayout.

33. viewpager setting spacing and caching

viewPager.setOffscreenPageLimit(TOTAL_COUNT);viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));

34. What does a level-1 cache and level-2 Cache mean ??
Static ram cache is called a level-1 cache, and later added dynamic RAM is called a level-2 cache.
There are two types of RAM,

One is static RAM and SRAM, and the other is dynamic RAM and DRAM. The storage speed of the former is much faster than that of the latter, and the memory we use is generally dynamic RAM. Some cainiao just said: to increase the system speed, can we just expand the cache? The larger the expansion, the more data cached, does the system get faster? The cache is usually static RAM, and the speed is very fast, but the static RAM integration is low (the same data is stored, static RAM is six times the size of dynamic RAM, and the price is high (static RAM with the same capacity is four times the size of dynamic RAM, expanding static RAM as a cache is a very stupid behavior, but in order to improve the system performance and speed, we must expand the cache, so there is a compromise, instead of expanding the original static RAM cache, it adds some high-speed dynamic RAM as the cache. These high-speed dynamic RAM is faster than conventional dynamic RAM, but slower than the original static RAM cache, we call the original static ram cache a level-1 cache, and the later added dynamic RAM a level-2 cache. The content in the first-level cache and second-level cache is copies (ing) of frequently accessed data in the memory. They exist to reduce high-speed CPU access to slow memory. Generally, the CPU can find data or commands in the order of first-level cache, second-level cache, or memory.

35. Performance Optimization: Use SparseArray instead of HashMap

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.