Summary of issues used with Android ScrollView and ListView

Source: Internet
Author: User

1.ScrollView nested ListView, touch event interception problem.

Reference http://www.cnblogs.com/lqminn/archive/2013/03/02/2940194.html
http://blog.csdn.net/chaihuasong/article/details/17499799

_scrollview.requestdisallowintercepttouchevent (true);

The meaning of this sentence is to tell ScrollView that the rolling events are handed to me for processing. Remember to return it when you're done.

_scrollview.requestdisallowintercepttouchevent (false);

If you do not set it back, ScrollView will not be able to scroll.

2.ScrollView scrolling, is the first entry in the ListView in the display state?

Reference http://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible

BooleanCheckneedrefresh () {Rect scrollbounds=NewRect (); View FirstChild= Listview.getchildat (0);        _scrollview.gethitrect (Scrollbounds); if(Firstchild.getlocalvisiblerect (scrollbounds)) {//Any portion of the firstchild, even a-pixel, is within the//Visible Window            return true; } Else {            //NONE of the firstchild is within the visible window            return false; }    }

3. The ListView cannot display the full

Reference http://blog.csdn.net/hahashui123/article/details/39177057
http://blog.csdn.net/solomonxiang/article/details/26507145

 Public Static voidSetlistviewheight (ListView listview) {Try {            intTotalheight = 0; ListAdapter Adapter=Listview.getadapter ();  for(inti = 0, Len = Adapter.getcount (); i < Len; i++) {//Listadapter.getcount ()View ListItem = Adapter.getview (i,NULL, ListView); Listitem.setlayoutparams (Newlayoutparams (layoutparams.wrap_content, layoutparams.wrap_content)); Listitem.measure (0, 0); Totalheight+=listitem.getmeasuredheight (); } viewgroup.layoutparams params=Listview.getlayoutparams (); Params.height=Totalheight+ (Listview.getdividerheight () * (Listview.getcount ()-1));        Listview.setlayoutparams (params); } Catch(Exception ex) {ex.printstacktrace (); }    }

Incidentally, the GridView

 Public Static voidSetgridviewheight (GridView GridView,intNumColumns) {        Try{ListAdapter Adapter=Gridview.getadapter (); introw = 3; View ListItem= Adapter.getview (0,NULL, GridView); if(ListItem = =NULL)                return; Listitem.setlayoutparams (Newlayoutparams (layoutparams.wrap_content, layoutparams.wrap_content)); Listitem.measure (0, 0); intTotalheight = Listitem.getmeasuredheight () *Row+ (Gridview.getverticalspacing () * (row-1)); Viewgroup.layoutparams params=Gridview.getlayoutparams (); Params.height=Totalheight;        Gridview.setlayoutparams (params); } Catch(Exception ex) {ex.printstacktrace (); }    }

If the ListView is with Bottomview

 Public Static voidSetlistviewheight (ListView listview) {Try {            intTotalheight = 0; intBottomheight = 0; ListAdapter DataAdapter=NULL; intTotalItems = 0; ListAdapter Adapter=Listview.getadapter (); if(Adapterinstanceofheaderviewlistadapter) {Headerviewlistadapter Headerviewlistadapter=((Headerviewlistadapter) adapter); DataAdapter=Headerviewlistadapter.getwrappedadapter (); TotalItems=Dataadapter.getcount (); intAllItems =Headerviewlistadapter.getcount (); View Bottomitem= Headerviewlistadapter.getview (allItems-1,                        NULL, ListView); Bottomitem.measure (0, 0); Bottomheight=bottomitem.getmeasuredheight (); } Else{DataAdapter=adapter; }             for(inti = 0, len = totalitems; i < Len; i++) {View ListItem= Dataadapter.getview (I,NULL, ListView); Listitem.setlayoutparams (Newlayoutparams (layoutparams.wrap_content, layoutparams.wrap_content)); Listitem.measure (0, 0); Totalheight+=listitem.getmeasuredheight (); }            intListviewcount =Listview.getcount (); intHeight =Totalheight+ (Listview.getdividerheight () * Listviewcount + 1)                    +Bottomheight; Viewgroup.layoutparams params=Listview.getlayoutparams (); Params.height=height;            Listview.setlayoutparams (params);                     Listview.requestlayout (); } Catch(Exception ex) {ex.printstacktrace (); }    }

4. Miscellaneous, custom control implementation ListView

Http://www.cnblogs.com/lesliefang/p/3587154.html

Summary of issues used with Android ScrollView and ListView

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.