当前位置: 首页>>代码示例>>Java>>正文


Java ListView.getDividerHeight方法代码示例

本文整理汇总了Java中android.widget.ListView.getDividerHeight方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.getDividerHeight方法的具体用法?Java ListView.getDividerHeight怎么用?Java ListView.getDividerHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.ListView的用法示例。


在下文中一共展示了ListView.getDividerHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * 计算ListView的高度, 重置ListView的高度.
 * 
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView)
{
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null)
	{
		return;
	}

	View listItem = null;
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++)
	{
		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));
	listView.setLayoutParams(params);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:27,代码来源:ViewUtils.java

示例2: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * Taken from Stack Overflow - https://stackoverflow.com/a/26501296
 * Updates the ListView height based on its children
 *
 * @param listView the ListView to adjust
 */

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
开发者ID:jthomperoo,项目名称:Forge,代码行数:28,代码来源:GeneratorFragment.java

示例3: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static 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 = 80 * (listAdapter.getCount() - 1);
    // params.height = 80 * (listAdapter.getCount());
    params.height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    ((ViewGroup.MarginLayoutParams) params).setMargins(0, 0, 0, 0);
    listView.setLayoutParams(params);

}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:21,代码来源:ExpandedListUtils.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        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));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
开发者ID:Elbehiry,项目名称:Viajes,代码行数:20,代码来源:Utils.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**** Method for Setting the Height of the ListView dynamically.
 **** Hack to fix the issue of not showing all the items of the ListView
 **** when placed inside a ScrollView  ****/
private static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        return;

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
    int totalHeight = 0;
    View view = null;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        view = listAdapter.getView(i, view, listView);
        if (i == 0)
            view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, WindowManager.LayoutParams.WRAP_CONTENT));

        view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
开发者ID:gbl08ma,项目名称:underlx,代码行数:25,代码来源:AboutFragment.java

示例6: setAdapterHeight

import android.widget.ListView; //导入方法依赖的package包/类
public static void setAdapterHeight(ListView listView){

        android.widget.ListAdapter listAdapter = listView.getAdapter();//1、获取adapter
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0,j =listAdapter.getCount(); i < j ; i++) {  //2、算出没一个item高度总和
            View listItem = listAdapter.getView(i , null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params=listView.getLayoutParams();
        params.height = totalHeight + listView.getPaddingBottom()   //3、加上listview自身每行间距属性
                + listView.getPaddingTop()
                + (listView.getDividerHeight() * (listAdapter.getCount() - 1));


        listView.setLayoutParams(params);//4、重新设置高
    }
 
开发者ID:aiyangtianci,项目名称:BluetoothAPP,代码行数:23,代码来源:ListViewHeightMesure.java

示例7: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * 修正listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    // 获取ListView对应的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount()返回数据项的数目
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0); // 计算子项View 的宽高
        totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1)));
    listView.setLayoutParams(lp);
}
 
开发者ID:wzc25151,项目名称:lrs_android,代码行数:20,代码来源:DisplayUtil.java

示例8: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/***
 * 动态设置listview的高度
 * 
 * @param 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.getDividerHeight()获取子项间分隔符占用的高度
	// params.height最后得到整个ListView完整显示需要的高度
	listView.setLayoutParams(params);
}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:27,代码来源:UserSettingFragment.java

示例9: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * 动态设置ListView的高度
 * @param listView ListView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    if(listView == null) return;

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        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));
    listView.setLayoutParams(params);
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:25,代码来源:ViewFinder.java

示例10: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @author sunglasses
 * @param listView
 * @category 计算listview高度
 */
public static 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));
	listView.setLayoutParams(params);
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:24,代码来源:Tools.java

示例11: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * @Title: setListViewHeightBasedOnChildren @Description:
 * TODO(根据ListView算出List的高度) @param @param mContext @param @param
 * listView 参数 @return void 返回类型 @throws
 */
public static void setListViewHeightBasedOnChildren(Context mContext, 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));
    listView.setLayoutParams(params);
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:22,代码来源:Utils.java

示例12: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView)
{
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
    {
        // pre-condition
        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));
    listView.setLayoutParams(params);
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:22,代码来源:MIP_ListViewHeight.java

示例13: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition  
        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));
    listView.setLayoutParams(params);
}
 
开发者ID:littleRich,项目名称:AutoInteraction-Library,代码行数:19,代码来源:Util.java

示例14: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
/**
 * 计算整个listview所占的高度
 *
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    // 获取ListView对应的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount()返回数据项的数目
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0); // 计算子项View 的宽高
        totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    // listView.getDividerHeight()获取子项间分隔符占用的高度
    // params.height最后得到整个ListView完整显示需要的高度
    listView.setLayoutParams(params);
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:24,代码来源:CommonUtils.java

示例15: setListViewHeightBasedOnChildren

import android.widget.ListView; //导入方法依赖的package包/类
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {
        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();
        }
        LayoutParams params = listView.getLayoutParams();
        params.height = (listView.getDividerHeight() * (listAdapter.getCount() - 1)) +
                totalHeight;
        listView.setLayoutParams(params);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:UIHelper.java


注:本文中的android.widget.ListView.getDividerHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。