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


Java ListAdapter.getView方法代码示例

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


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

示例1: measureHeight

import android.widget.ListAdapter; //导入方法依赖的package包/类
private int measureHeight(int measureSpec) {
	int mode = MeasureSpec.getMode(measureSpec);
	if (mode == MeasureSpec.AT_MOST) {
		return MeasureSpec.makeMeasureSpec(measureSpec, mode);
	} else if (mode == MeasureSpec.EXACTLY) {
		ListAdapter adapter = getAdapter();
		if (adapter == null) {
			measureSpec = 0;
		} else {
			int result = 0;
			for (int i = 0; i < adapter.getCount(); i++) {
				View contentView = adapter.getView(i, null, null);
				contentView.measure(0, 0);
				result += contentView.getMeasuredHeight();
			}
			measureSpec = result + getDividerHeight()
					* (adapter.getCount() - 1);
		}
	}

	return MeasureSpec.makeMeasureSpec(measureSpec, mode);
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:23,代码来源:SuperListView.java

示例2: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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

示例3: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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:Lazyeraser,项目名称:DereHelper,代码行数:19,代码来源:Utils.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的package包/类
/**
 * @param listView
 * @author sunglasses
 * @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:TAnsz,项目名称:MyTvLauncher,代码行数:24,代码来源:Tools.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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

示例6: getView

import android.widget.ListAdapter; //导入方法依赖的package包/类
/**
 * Get a View that displays the data at the specified
 * position in the data set.
 *
 * @param position    Position of the item whose data we want
 * @param convertView View to recycle, if not null
 * @param parent      ViewGroup containing the returned View
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    for (ListAdapter piece : getPieces()) {
        int size = piece.getCount();

        if (position < size) {

            return (piece.getView(position, convertView, parent));
        }

        position -= size;
    }

    return (null);
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:24,代码来源:MergeAdapter.java

示例7: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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

示例8: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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

示例9: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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

示例10: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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,代码来源:EditSchoolActivity.java

示例11: setGridViewHeightByChildren

import android.widget.ListAdapter; //导入方法依赖的package包/类
/**
 * 根据子item的高度 动态测量GridView的实际高度
 * @param gridView
 */
public static void setGridViewHeightByChildren(GridView gridView) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    //总高度
    int totalHeight = 0;
    int lineNum = gridView.getNumColumns(); //得到布局文件中设置的一行显示几个
    View item = listAdapter.getView(0,null,gridView);
    item.measure(0,0); //计算子item的高度
    //得到总高度
    totalHeight = item.getMeasuredHeight()*lineNum;

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight;
    gridView.setLayoutParams(params);
}
 
开发者ID:yinyiliang,项目名称:RabbitCloud,代码行数:22,代码来源:SmallToolsHelper.java

示例12: getListViewParams

import android.widget.ListAdapter; //导入方法依赖的package包/类
/**
 * 动态的算出ListView实际的LayoutParams 最关键的是算出LayoutParams.height
 */
private void getListViewParams() {
    // 通过ListView获取其中的适配器adapter
    ListAdapter listAdapter = lv_res.getAdapter();
    if (listAdapter == null) {
        return;
    }
    // 声明默认高度为0
    int totalHeight = 0;
    // 遍历listView中所有Item,累加所有item的高度就是ListView的实际高度(后面会考虑分割线的高度)
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View item = listAdapter.getView(i, null, lv_res);
        item.measure(0, 0);
        totalHeight += item.getMeasuredHeight();
    }
    ViewGroup.LayoutParams lp = lv_res.getLayoutParams();
    lp.height = totalHeight
            + (lv_res.getDividerHeight() * (listAdapter.getCount() - 1));
    lv_res.setLayoutParams(lp);
}
 
开发者ID:android-app-development-course,项目名称:fruit,代码行数:23,代码来源:EyeResultActivity.java

示例13: measureHeight

import android.widget.ListAdapter; //导入方法依赖的package包/类
private int measureHeight() {
    // get ListView adapter
    ListAdapter adapter = mListView.getAdapter();
    if (null == adapter) {
        return 0;
    }

    int totalHeight = 0;

    for (int i = 0, len = adapter.getCount(); i < len; i++) {
        View item = adapter.getView(i, null, mListView);
        if (null == item) continue;
        // measure each item width and height
        item.measure(0, 0);
        // calculate all height
        totalHeight += item.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = mListView.getLayoutParams();

    if (null == params) {
        params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    // calculate ListView height
    params.height = totalHeight + (mListView.getDividerHeight() * (adapter.getCount() - 1));

    mListView.setLayoutParams(params);

    return params.height;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:XScrollViewActivity.java

示例14: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //导入方法依赖的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,代码来源:ListViewUtils.java

示例15: getWrapHeight

import android.widget.ListAdapter; //导入方法依赖的package包/类
/**
 * 计算 ListView 自适应高度
 * @param listView
 * @return
 */
public static int getWrapHeight(ListView listView){
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return 0;
    }
    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();
    }
    totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    return totalHeight;
}
 
开发者ID:42Chapters,项目名称:AdaptationX-android,代码行数:20,代码来源:ListViewManager.java


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