Android ListView and ScrollView conflict issues

Source: Internet
Author: User

Recently made an app, which has an interface similar to the comments feature of Weibo, first lists the text content and pictures of the microblog, and then the comments below. I started with a scrollview to wrap the main content and the ListView, and then add the contents of each control (yes, it feels a bit like the edit interface of this CSDN blog), 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, and finally ScrollView get the focus, the ListView can not slide. The most common solution on the web is to use getmeasure to calculate the height of each entry and split line when loading the ListView, and then add the result to the height of the ListView control, but it seems to apply only to the same height of each entry in the ListView (without trying, It's strange why this is so. It's either customizing a control that inherits from the ListView, and setting the height of the ListView in advance, but it's always a hassle, 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 to compare the method of speculation, is in the adapter of the ListView GetView method according to position structure different interface, that is, if the 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. Later do not want to see if there is a better way to achieve, to find a overflow, found that someone recommended the method and I almost, so think this method is relatively good, do not need to do extra work, Only need to put inflate's work by the main activity in the adapter.


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;}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.