• ScrollView和ListView的冲突问题


    在ScrollView添加一个ListView会导致listview控件显示不全,这是因为两个控件的滚动事件冲突导致。所以需要通过listview中的item数量去计算listview的显示高度,从而使其完整展示,如下提供一个方法供大家参考。

    示例代码:

    public void setListViewHeightBasedOnChildren(ListView listView) { 
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) { 
    return; 
    } 
     
    int totalHeight = 0; 
    for (int i = 0; i < listAdapter.getCount(); i++) { 
    View listItem = listAdapter.getView(i, null, listView); 
    listItem.measure(0, 0); 
    totalHeight += listItem.getMeasuredHeight(); 
    } 
     
    ViewGroup.LayoutParams params = listView.getLayoutParams(); 
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
    params.height += 5;//if without this statement,the listview will be a little short 
    listView.setLayoutParams(params); 
    }
  • 相关阅读:
    Kefa and Park
    分土地
    果园里的树
    分解质因数
    素数筛
    cantor的数表
    new一个二维数组
    基础练习 十六进制转八进制
    查函数功能
    concatenate函数
  • 原文地址:https://www.cnblogs.com/yaxiaoke/p/5362942.html
Copyright © 2020-2023  润新知