The six holes in Android development: several tips on view

Source: Internet
Author: User

These points, not a pit, but it really wasted some of my time


1, ScrollView High set into "wrap_content" will shrink very small,

Only one view within the ScrollView is allowed, and do not set his height to "wrap_content", otherwise it will shrink to a very short look.

The ListView is the same.


2. If the item in the ListView has a different style, it is best to use getitemviewtype() to distinguish

In fact, the ListView item can be used to control visiable/gone in a single view layout, resulting in different itemview.

However, there are some disadvantages, 1 is the logic of the GetView () method is somewhat complex, 2 is likely to waste some inflate time, because some of the view is to be gone off, must be displayed should not be inflate, Inflate requires IO, and IO is a time-consuming operation. 3 waste of memory, since it is not necessary to display, it should not have this object.

Baseadapter is born with the ability to differentiate Itemview, overriding the Getitemviewtype () method and Getviewtypecount () can be implemented. At the same time in GetView () only need a simple switch-case can handle different itemview.


3. The ImageView does not fit the width first and then fits the height according to the width of the model.

The pit has been trampled two times. Always thought Android was strong enough, but it really didn't do it.

ImageView has many image scaling modes, but there is no pattern that fits the width of the first fit, and then the effect of the height to fit the width . After trying a lot of pattern combinations, understand this point. So to do this, only honestly according to the screen width, calculate the appropriate width of the picture, and then according to the picture of the width and height of the picture to calculate the height, set to iamgeview width and height.


The six holes in Android development: several tips on view

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.