Optimal Solution for ScrollView nested ListView conflicts, scrollviewlistview

Source: Internet
Author: User

Optimal Solution for ScrollView nested ListView conflicts, scrollviewlistview

After the project is done, you will find that ScrollView nesting ListVew or GridView is very common, but you will also find various strange problems. Based on your personal experience, it is now the easiest way to list common problems and code.

Question 1: The ListVew data nested in the ScrollView is not fully displayed. I encountered a maximum of two existing data entries.

Solution: rewrite ListVew or GridView. There are still many solutions on the Internet, but they are not easy to use or complex.

@ Override

/** Only override this method to make ListView adapt to ScrollView */

Protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec ){

Int expandSpec = MeasureSpec. makeMeasureSpec (Integer. MAX_VALUE> 2,

MeasureSpec. AT_MOST );

Super. onMeasure (widthMeasureSpec, expandSpec );

}

Question 2Open the page layout of ScrollView with ListVew. The default start position is not the top.

There are two solutions that are quite useful:

First, you can set the Gridview or ListVew in it to avoid getting the focus.

Gridview. setFocusable (false); listview. setFocusable (false );

Note: Setting android: focusable = "false" in xml layout does not take effect.

Method 2: You can set myScrollView. smoothScrollTo () on the Internet );

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.