当前位置:网站首页>Treatment of incomplete display of listview height
Treatment of incomplete display of listview height
2022-04-23 18:42:00 【Xiao Xiaofeng】
listview Show incomplete scene :
1、listview(scrollview...) nesting listview, Inside listview Incomplete height display
2、 The dynamic change listview Of item Layout ,listview Incomplete height display
Handle :
stay listview After adding an adapter , Dynamic computing listview Height and set the height .
The method is as follows :
/**
* Dynamic setting listview Height
*
* @param listView
* @param h
*/
public static void setListViewHeightBasedOnChildren(ListView listView) {
// obtain ListView Corresponding Adapter
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = 0;
listView.setLayoutParams(params);
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount() Returns the number of data items
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0); // Calculate the children View The width and height of
totalHeight += listItem.getMeasuredHeight(); // Count the total height of all subitems
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1))
+ listView.getPaddingBottom() + listView.getPaddingTop();
// listView.getDividerHeight() Gets the height occupied by the separator between children
// params.height And finally get the whole ListView Full display of required height
listView.setLayoutParams(params);
}
If the above still cannot be solved , Please check listview Of item Layout :
The height of the outermost control must be set to The adaptive (wrap_content) or fill (match_parent)
example :
Original layout :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="148px"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="50px"
android:paddingRight="50px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" name " android:textSize="44px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50px"
android:layout_weight="1"
android:drawablePadding="50px"
android:drawableRight="@drawable/ic_crumb"
android:gravity="right"
android:text=""
android:textSize="44px" />
</LinearLayout>
It is amended as follows :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="148px"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="50px"
android:paddingRight="50px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" name "
android:textSize="44px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50px"
android:layout_weight="1"
android:drawablePadding="50px"
android:drawableRight="@drawable/ic_crumb"
android:gravity="right"
android:text=""
android:textSize="44px" />
</LinearLayout>
</LinearLayout>
版权声明
本文为[Xiao Xiaofeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210604091385.html
边栏推荐
- Kettle paoding jieniu Chapter 17 text file output
- ESP32 LVGL8. 1 - img picture (IMG 20)
- Daily network security certification test questions (April 13, 2022)
- Daily CISSP certification common mistakes (April 12, 2022)
- 机器学习理论基础篇--关于机器学习的一些术语
- Domestic GD chip can filter
- Cutting permission of logrotate file
- With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
- 配置iptables
- 7、 DOM (Part 2) - chapter after class exercises and answers
猜你喜欢
PyGame tank battle
Halo open source project learning (VII): caching mechanism
Custom prompt box MessageBox in QT
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
QT tablewidget insert qcombobox drop-down box
7、 DOM (Part 2) - chapter after class exercises and answers
On iptables
视频边框背景如何虚化,简单操作几步实现
【科普】CRC校验(一)什么是CRC校验?
随机推荐
Database computer experiment 4 (data integrity and stored procedure)
程序员如何快速开发高质量的代码?
七、DOM(下) - 章节课后练习题及答案
昇腾 AI 开发者创享日全国巡回首站在西安成功举行
数据库上机实验四(数据完整性与存储过程)
Ionic 从创建到打包指令集顺序
Feature selection feature_ selection--SelectKBest
QT add external font ttf
Nacos作为服务配置中心实战
Keil RVMDK compiled data type
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Practice of Druid SQL and security in meituan review
Excel intercept text
MVVM模型
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
22 year flying Book manpower Kit
实战业务优化方案总结---主目录---持续更新
C language simulates entering and leaving the stack, first in first out, first in first out, shared memory
Promote QT default control to custom control
CANopen usage method and main parameters of object dictionary