package com.game.webgame.view;

import android.view.View;
import android.widget.Adapter;
import android.widget.ListView;

/**
 * Created by Administrator on 2017/4/24.
 */

public class ListViewUtils {
    //TODO 解决ScollView、GridView及Expandlistview嵌套ListView显示不全问题
    /*******************************************************************/
    private  int totalHeight = 0;

    public  int setListViewHeight(ListView listView){
        /*得到适配器*/
        Adapter adapter = listView.getAdapter();

        /*遍历控件*/
        for (int i = 0; i < adapter .getCount(); i++) {
            View view = adapter.getView(i, null, listView);
            /*测量一下子控件的高度*/
            view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            totalHeight+=view.getMeasuredHeight();
        }

        /*控件之间的间隙*/
        totalHeight+=listView.getDividerHeight()*(listView.getCount()-1);

//        /*2、赋值给ListView的LayoutParams对象*/
//        ViewGroup.LayoutParams params = listView.getLayoutParams();
//        params.height = totalHeight;
//
//        listView.setLayoutParams(params);
        return totalHeight;

    }
}
