Solution to incomplete display of ListView nested GridView

Source: Internet
Author: User

Solution to incomplete display of ListView nested GridView

Reprinted with the source: http://blog.csdn.net/allen315410/article/details/40152987

Recently, in a project, a module needs to nest a GridView in the ListView to create the "Nine Squares" effect. As a result, the child element on the GridView only shows one row, but not the complete description, for example:


In fact, a total of six images need to be displayed on the ListView. That is to say, three images need to be displayed in the next row. The result of the GridView is not completely displayed. This is a strange problem, however, the solution is to rewrite a GridView, create a custom GridView, and then rewrite the onmeasurespec (int widthMeasureSpec, int heightMeasureSpec) method of the GridView, and remeasure the GridView, and specify the new height of the GridView. The Code is as follows: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;"> import android. content. context; import android. util. attributeSet; import android. widget. gridView;/*** custom "nine cells" -- Used in the image set for displaying the details of a post * solve the problem: the GridView display is incomplete and only displays a row of images, which is strange, try to override the GridView to solve ** @ author lichao * @ since 2014-10-16 16:41 **/public class SodukuGridView extends GridView {public SodukuGridView (Context context) {super (context ); // TODO Auto-generated constructor stub} public SodukuGridView (Context context, AttributeSet attrs) {super (context, attrs ); // TODO Auto-generated constructor stub} public SodukuGridView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle ); // TODO Auto-generated constructor stub} @ Overrideprotected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {// TODO Auto-generated method stubint expandSpec = MeasureSpec. makeMeasureSpec (Integer. MAX_VALUE> 2, MeasureSpec. AT_MOST); super. onMeasure (widthMeasureSpec, expandSpec );}}The layout file is as follows:

     
 

Then use the custom GridView as a normal GridView. The problem is solved:


Well, this is the solution. I don't know if it is better. I look forward to discussing it together!



Related Article

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.