android中怎么让listview的内容全部显示出来
2015-04-18 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517165
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
注意,如果listitem里面有textview的话,就当一行处理进行截取数字。
public static void setListViewHeightBasedOnChildren(ListView listView) {
// 获取ListView对应的Adapter WeiboContentAdapter listAdapter = (WeiboContentAdapter) listView.getAdapter(); if (listAdapter == null) { return; } Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Align.LEFT); LinearLayout listItem; TextView tvContent; int totalHeight = 0; int lineCount = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 listItem = (LinearLayout)listAdapter.getView(i, null, listView); tvContent = (TextView) listItem.findViewById(R.id.tv_weibo_detail_content); lineCount = getLineCount(mPaint, ((SpannedString) tvContent.getText()).toString()); tvContent.measure(0, 0); // 计算子项View 的宽高 totalHeight += tvContent.getMeasuredHeight()*lineCount + 60; // 统计所有子项的总高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) ; // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
private static int getLineCount(Paint mPaint, String content) { int index; int count = 0; while(content.length() > 0){ index = mPaint.breakText(content, true, ResolutionUtil.getWPx()/2, null); content = content.substring(index); count++; } return count; }
/** * 动态改变listView的高度 * @param pull */ private void setPullLvHeight(ListView pull){ int totalHeight = 0; for (int i = 0, len = adapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目 View listItem = adapter.getView(i, null, pull); listItem.measure(0, 0); //计算子项View 的宽高 totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度 } ViewGroup.LayoutParams params = pull.getLayoutParams(); params.height = totalHeight + (pull.getDividerHeight() * (pull.getCount() - 1)); pull.setLayoutParams(params); }
public static void setListViewHeightBasedOnChildren(ListView listView) {
// 获取ListView对应的Adapter WeiboContentAdapter listAdapter = (WeiboContentAdapter) listView.getAdapter(); if (listAdapter == null) { return; } Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Align.LEFT); LinearLayout listItem; TextView tvContent; int totalHeight = 0; int lineCount = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 listItem = (LinearLayout)listAdapter.getView(i, null, listView); tvContent = (TextView) listItem.findViewById(R.id.tv_weibo_detail_content); lineCount = getLineCount(mPaint, ((SpannedString) tvContent.getText()).toString()); tvContent.measure(0, 0); // 计算子项View 的宽高 totalHeight += tvContent.getMeasuredHeight()*lineCount + 60; // 统计所有子项的总高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) ; // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
private static int getLineCount(Paint mPaint, String content) { int index; int count = 0; while(content.length() > 0){ index = mPaint.breakText(content, true, ResolutionUtil.getWPx()/2, null); content = content.substring(index); count++; } return count; }
/** * 动态改变listView的高度 * @param pull */ private void setPullLvHeight(ListView pull){ int totalHeight = 0; for (int i = 0, len = adapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目 View listItem = adapter.getView(i, null, pull); listItem.measure(0, 0); //计算子项View 的宽高 totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度 } ViewGroup.LayoutParams params = pull.getLayoutParams(); params.height = totalHeight + (pull.getDividerHeight() * (pull.getCount() - 1)); pull.setLayoutParams(params); }
展开全部
一、获取并设置ListView内容的高度:
复制内容到剪贴板
二、通过设置标签,来响应具体操作:
1.定义标签,及点击后的处理方法
复制内容到剪贴板
2.监听ListView点击设置
复制内容到剪贴板代3.自定义DevAdapter,主要添加了存储tags内容和获取点击项tag内容,以确定点击操作,供 2 使用。复制内容到剪贴板
4.添加ListView项时,对应添加tag到tags中
复制内容到剪贴板
注意:listView中的adapter里的getview中的view,只能是单个view 或是线性布局,不能为相对布局(可把相对布局放在线性布局中).
复制内容到剪贴板
二、通过设置标签,来响应具体操作:
1.定义标签,及点击后的处理方法
复制内容到剪贴板
2.监听ListView点击设置
复制内容到剪贴板代3.自定义DevAdapter,主要添加了存储tags内容和获取点击项tag内容,以确定点击操作,供 2 使用。复制内容到剪贴板
4.添加ListView项时,对应添加tag到tags中
复制内容到剪贴板
注意:listView中的adapter里的getview中的view,只能是单个view 或是线性布局,不能为相对布局(可把相对布局放在线性布局中).
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-12-16 · 知道合伙人数码行家
关注
展开全部
注意,如果listitem里面有textview的话,就当一行处理进行截取数字。
public static void setListViewHeightBasedOnChildren(ListView listView) {
// 获取ListView对应的Adapter WeiboContentAdapter listAdapter = (WeiboContentAdapter) listView.getAdapter(); if (listAdapter == null) { return; } Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Align.LEFT); LinearLayout listItem; TextView tvContent; int totalHeight = 0; int lineCount = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 listItem = (LinearLayout)listAdapter.getView(i, null, listView); tvContent = (TextView) listItem.findViewById(R.id.tv_weibo_detail_content); lineCount = getLineCount(mPaint, ((SpannedString) tvContent.getText()).toString()); tvContent.measure(0, 0); // 计算子项View 的宽高 totalHeight += tvContent.getMeasuredHeight()*lineCount + 60; // 统计所有子项的总高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) ; // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
private static int getLineCount(Paint mPaint, String content) { int index; int count = 0; while(content.length() > 0){ index = mPaint.breakText(content, true, ResolutionUtil.getWPx()/2, null); content = content.substring(index); count++; } return count; }
/** * 动态改变listView的高度 * @param pull */ private void setPullLvHeight(ListView pull){ int totalHeight = 0; for (int i = 0, len = adapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目 View listItem = adapter.getView(i, null, pull); listItem.measure(0, 0); //计算子项View 的宽高 totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度 } ViewGroup.LayoutParams params = pull.getLayoutParams(); params.height = totalHeight + (pull.getDividerHeight() * (pull.getCount() - 1)); pull.setLayoutParams(params); }
public static void setListViewHeightBasedOnChildren(ListView listView) {
// 获取ListView对应的Adapter WeiboContentAdapter listAdapter = (WeiboContentAdapter) listView.getAdapter(); if (listAdapter == null) { return; } Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Align.LEFT); LinearLayout listItem; TextView tvContent; int totalHeight = 0; int lineCount = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 listItem = (LinearLayout)listAdapter.getView(i, null, listView); tvContent = (TextView) listItem.findViewById(R.id.tv_weibo_detail_content); lineCount = getLineCount(mPaint, ((SpannedString) tvContent.getText()).toString()); tvContent.measure(0, 0); // 计算子项View 的宽高 totalHeight += tvContent.getMeasuredHeight()*lineCount + 60; // 统计所有子项的总高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) ; // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
private static int getLineCount(Paint mPaint, String content) { int index; int count = 0; while(content.length() > 0){ index = mPaint.breakText(content, true, ResolutionUtil.getWPx()/2, null); content = content.substring(index); count++; } return count; }
/** * 动态改变listView的高度 * @param pull */ private void setPullLvHeight(ListView pull){ int totalHeight = 0; for (int i = 0, len = adapter.getCount(); i < len; i++) { //listAdapter.getCount()返回数据项的数目 View listItem = adapter.getView(i, null, pull); listItem.measure(0, 0); //计算子项View 的宽高 totalHeight += listItem.getMeasuredHeight(); //统计所有子项的总高度 } ViewGroup.LayoutParams params = pull.getLayoutParams(); params.height = totalHeight + (pull.getDividerHeight() * (pull.getCount() - 1)); pull.setLayoutParams(params); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询