Android ListView and ScrollView conflict issues

Source: Internet
Author: User

A recent app, which has a microblogging-like Comment feature interface, first lists the text content and pictures of the microblog. Then there is the comment below.

Start with a scrollview to wrap up the main content and the ListView in the comment area. Then add the contents of the individual controls (yes, it feels a bit like the CSDN blog's editing interface), but after writing it, I find that the ListView only shows the height of an entry. And can not slide, search the Internet to find the reason is that ScrollView and the ListView are sliding, put them in a piece will conflict. Finally, ScrollView got the focus. The ListView cannot be slid. The most common solution on the web is to use getmeasure to calculate the height of each entry and cut line when loading a ListView, then add the result to the height of the ListView control, just as if it were only applicable to the same height of each item in the ListView (not tried. Very strange why this is so). Either you define a control that inherits from the ListView, and it is the height of the ListView set beforehand. But it's always more troublesome. And the accuracy is not as good as the system itself.

Lazy cancer attack really do not want to do these things, so I would like to try a more speculative method, that is, in the adapter of the ListView GetView method based on position constructs a different interface, that is, assuming that position is 0, then use the original main information (micro-bo text, image) of the XML file take inflate Convertview, or use the comment entry XML to inflate, after testing is feasible. Then do not forget to see if there is a better way to achieve. Went to overflow to find a bit, found that someone recommended the method is almost the same as mine. So I think that this method is better, do not need to do extra work, just need to put inflate's work by the main activity in the adapter can be.


GetView method

@Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {/* Main information interface */if (0 = = position) {Mainholder Holder = Null;convertview = Inflater.inflate (R.layout.info, parent, false); holder = new Mainholder (); Convertview.settag (holder);               ······} /* Comment interface */else{itemholder holder = Null;convertview = Inflater.inflate (R.layout.item, parent, false); holder = new Itemholder (); Convertview.settag (holder); return Convertview;}}


Android ListView and ScrollView conflict issues

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.