当前位置:网站首页>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
边栏推荐
- Keil RVMDK compiled data type
- Daily network security certification test questions (April 14, 2022)
- Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
- 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
- Nacos作为服务注册中心
- Nacos集群搭建和mysql持久化配置
- Connection mode of QT signal and slot connect() and the return value of emit
- Iptables - L executes slowly
- QT add external font ttf
- STM32: LCD display
猜你喜欢

Stm32mp157 wm8960 audio driver debugging notes

ESP32 LVGL8. 1 - textarea text area (textarea 26)

Halo open source project learning (VII): caching mechanism

STM32: LCD display

Esp32 (UART event) - serial port event learning (1)

In win10 system, all programs run as administrator by default

ctfshow-web361(SSTI)

iptables -L执行缓慢
![[popular science] CRC verification (I) what is CRC verification?](/img/80/a1fa10ce6781aebf1b53d91fba52f4.png)
[popular science] CRC verification (I) what is CRC verification?
![[mathematical modeling] - analytic hierarchy process (AHP)](/img/ff/2350c9604a03fff6a6a751aa3cfa3b.png)
[mathematical modeling] - analytic hierarchy process (AHP)
随机推荐
ctfshow-web362(SSTI)
Nacos作为服务配置中心实战
QT excel operation summary
CANopen STM32 transplantation
机器学习实战 -朴素贝叶斯
Daily network security certification test questions (April 13, 2022)
【数学建模】—— 层次分析法(AHP)
K210 serial communication
CISSP certified daily knowledge points (April 18, 2022)
QT error: no matching member function for call to ‘connect‘
Ionic 从创建到打包指令集顺序
listener.log
RPM包管理
ESP32 LVGL8. 1 - calendar (calendar 25)
K210串口通信
七、DOM(下) - 章节课后练习题及答案
C language simulates entering and leaving the stack, first in first out, first in first out, shared memory
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Daily CISSP certification common mistakes (April 12, 2022)
Keil RVMDK compiled data type