Get the App
SLTechnology News&Howtos  ›  Development  › 

What if the ListView display is incomplete due to the nested use of ScrollView and ListView

Shulou Source: shulou.com Published: 2022-06-03 16:20:52 11月14日 Update

This article will explain in detail about ScrollView and ListView nested use caused ListView display incomplete how to do, Xiaobian think quite practical, so share to everyone as a reference, I hope you can read this article after harvest.

solutions

Actively calculate and set the height of ListView, so that you can reasonably display the height of ListView. The code is as follows:

public void setListViewHeightBasedOnChildren(ListView listView) { //Get ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; // listAdapter.getCount() Returns the number of data items for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); //calculate the width and height of the child View listItem.measure(0, 0); //count the total height of all children totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight +(listView.getDividerHeight() *(listAdapter.getCount()-1)); // listView.getDividerHeight() Get the height occupied by separators between subitems// params.height Finally get the height required for the complete display of the entire ListView listView.setLayoutParams(params);} About "ScrollView and ListView nested use lead to ListView display incomplete how to do" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Height subitems articles what to do more good practical initiative code content delimiters data data items number articles solutions knowledge solutions references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Huawei Microsoft vpn