zoukankan      html  css  js  c++  java
  • 获取并设置ListView高度的方法

     

    01 public void setListViewHeightBasedOnChildren(ListView listView) { 
    02     ListAdapter listAdapter = listView.getAdapter();  
    03     if (listAdapter == null) { 
    04         return
    05     
    06  
    07     int totalHeight = 0
    08     for (int i = 0; i < listAdapter.getCount(); i++) { 
    09         View listItem = listAdapter.getView(i, null, listView); 
    10         listItem.measure(00); 
    11         totalHeight += listItem.getMeasuredHeight(); 
    12     
    13  
    14     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
    15     params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
    16     ((MarginLayoutParams)params).setMargins(10101010);
    17     listView.setLayoutParams(params); 
    18 }
     

    [2].[代码] XML布局 跳至 [1] [2] [3] [4]

    01 <ScrollView
    02         android:layout_width="fill_parent"
    03         android:layout_height="fill_parent"
    04         android:fadingEdge = "none"
    05         android:background="#FFF4F4F4"
    06         xmlns:android="http://schemas.android.com/apk/res/android"
    07         >
    08    <LinearLayout
    09     android:gravity="center_horizontal"
    10     android:orientation="vertical"
    11     android:background="#fff4f4f4"
    12     android:layout_width="fill_parent"
    13     android:layout_height="fill_parent"
    14     >
    15     <ListView
    16         android:id="@+id/moreItemsListView"
    17         android:layout_width="fill_parent"
    18         android:layout_height="fill_parent"
    19         android:cacheColorHint="#FFF4F4F4"
    20         android:dividerHeight="0.0dip"
    21         android:fadingEdge="none"
    22         />
    23    </LinearLayout>
    24 </ScrollView>
     

    [3].[图片] scrollview_listview.jpg 跳至 [1] [2] [3] [4]

     
    路漫漫其修远兮 吾将上下而求索
  • 相关阅读:
    【python】元组
    【python】列表
    1-读书的网站
    35-Python
    34-TypeError: BoxSizer.AddSpacer(): argument 1 has unexpected type 'tuple'
    33-wxpython多个frame之间的信息共享
    32-python代码打包成exe文件-pyinstaller
    31-字符串转为 url 格式的两种不同情况
    30-python3 中 bytes 和 string 之间的互相转换
    9-eclispe中右键BuildPath没有了
  • 原文地址:https://www.cnblogs.com/hudabing/p/3185880.html
Copyright © 2011-2022 走看看