当前位置:网站首页>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
边栏推荐
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- 使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
- Deeply understand what new and make in golang are and what are the differences?
- Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
- ESP32 LVGL8. 1 - bar progress bar (bar 21)
- Domestic GD chip can filter
- STM32: LCD显示
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- Can filter
- 机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
猜你喜欢
listener.log
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Machine learning practice - naive Bayes
ESP32 LVGL8. 1 - arc (arc 19)
MVVM model
ESP32 LVGL8. 1 - input devices (input devices 18)
ESP32 LVGL8. 1 - calendar (calendar 25)
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
Stm32mp157 wm8960 audio driver debugging notes
随机推荐
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
根据快递单号查询物流查询更新量
CISSP certified daily knowledge points (April 12, 2022)
Introduction to ROS learning notes (II)
Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
QT curve / oscilloscope customplot control
ctfshow-web362(SSTI)
Daily CISSP certification common mistakes (April 14, 2022)
SQL database syntax learning notes
机器学习实战 -朴素贝叶斯
程序员如何快速开发高质量的代码?
Sentinel规则持久化进Nacos
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
iptables -L执行缓慢
About the operation of unit file reading (I)
[popular science] CRC verification (I) what is CRC verification?
os_ authent_ Prefix
ESP32 LVGL8. 1 - anim animation (anim 16)
Seata handles distributed transactions
特征选择feature_selection--SelectKBest