不滚动的listView(解决带head foot 计算)
来源:互联网 发布:有关教学视频的软件 编辑:程序博客网 时间:2024/06/07 07:26
package test.test;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
/**
* 不滚动的listView 即全部显示
*
* @author david
* @deprecated
* @see ComponentUtils.setListViewHeightBasedOnChildren
*/
@Deprecated
public class NoScrollListView extends ListView {
public NoScrollListView(Context paramContext) {
super(paramContext);
}
public NoScrollListView(Context paramContext, AttributeSet paramAttributeSet) {
super(paramContext, paramAttributeSet);
}
public NoScrollListView(Context paramContext,
AttributeSet paramAttributeSet, int paramInt) {
super(paramContext, paramAttributeSet, paramInt);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec,
MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));
ListAdapter listAdapter = getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
int height;
int footCount = getFooterViewsCount();
int headCount = getHeaderViewsCount();
int adapterCount = listAdapter.getCount();
int childCount = getChildCount();
Log.e("~~~~", "getChildCount():" + childCount + ",getAdapterCount():"
+ adapterCount);
Log.e("~~~~", "footCount:" + footCount + ",headCount:" + headCount);
for (int j = 0; j < childCount; j++) {
Log.e("all child ", "child :" + j + ",height:"
+ getChildAt(j).getHeight());
}
for (int i = 0; i < adapterCount; i++) { // listAdapter.getCount()返回数据项的数目
View listItem = null;
if (childCount > 0) // 只有childCount 存在时候才使用已有的子件直接计算
{
if (footCount > 0 && i >= adapterCount - footCount) {// 获取listItem
// footer部分
listItem = getChildAt((i - adapterCount) + childCount);
} else if (i >= childCount - footCount)
listItem = getChildAt(i + headCount + footCount); // 在listView内foothead的子项index都是前面的
else
listItem = getChildAt(i);
}
height = 0;
if (listItem == null) {
listItem = listAdapter.getView(i, null, this);
try {
listItem.measure(MeasureSpec.UNSPECIFIED,
MeasureSpec.UNSPECIFIED); // 计算子项View 的宽高
height = listItem.getMeasuredHeight();
} catch (Throwable t) {
t.printStackTrace();
}
} else
height = listItem.getHeight();
Log.v("TAG", "listAdapter row " + i + "height:" + height);
totalHeight += height; // 统计所有子项的总高度
}
// 总高度 每个item总高度 + 子项间隔总和 +头部缩进 + 底部缩进
totalHeight = totalHeight
+ (getDividerHeight() * (listAdapter.getCount() - 1))
+ getPaddingBottom() + getPaddingTop();
// Log.v(TAG, "params.height" + params.height);
// // listView.getDividerHeight()获取子项间分隔符占用的高度
//
// // params.height最后得到整个ListView完整显示需要的高度
setMeasuredDimension(getMeasuredWidth(), totalHeight);
}
}
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
/**
* 不滚动的listView 即全部显示
*
* @author david
* @deprecated
* @see ComponentUtils.setListViewHeightBasedOnChildren
*/
@Deprecated
public class NoScrollListView extends ListView {
public NoScrollListView(Context paramContext) {
super(paramContext);
}
public NoScrollListView(Context paramContext, AttributeSet paramAttributeSet) {
super(paramContext, paramAttributeSet);
}
public NoScrollListView(Context paramContext,
AttributeSet paramAttributeSet, int paramInt) {
super(paramContext, paramAttributeSet, paramInt);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec,
MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));
ListAdapter listAdapter = getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
int height;
int footCount = getFooterViewsCount();
int headCount = getHeaderViewsCount();
int adapterCount = listAdapter.getCount();
int childCount = getChildCount();
Log.e("~~~~", "getChildCount():" + childCount + ",getAdapterCount():"
+ adapterCount);
Log.e("~~~~", "footCount:" + footCount + ",headCount:" + headCount);
for (int j = 0; j < childCount; j++) {
Log.e("all child ", "child :" + j + ",height:"
+ getChildAt(j).getHeight());
}
for (int i = 0; i < adapterCount; i++) { // listAdapter.getCount()返回数据项的数目
View listItem = null;
if (childCount > 0) // 只有childCount 存在时候才使用已有的子件直接计算
{
if (footCount > 0 && i >= adapterCount - footCount) {// 获取listItem
// footer部分
listItem = getChildAt((i - adapterCount) + childCount);
} else if (i >= childCount - footCount)
listItem = getChildAt(i + headCount + footCount); // 在listView内foothead的子项index都是前面的
else
listItem = getChildAt(i);
}
height = 0;
if (listItem == null) {
listItem = listAdapter.getView(i, null, this);
try {
listItem.measure(MeasureSpec.UNSPECIFIED,
MeasureSpec.UNSPECIFIED); // 计算子项View 的宽高
height = listItem.getMeasuredHeight();
} catch (Throwable t) {
t.printStackTrace();
}
} else
height = listItem.getHeight();
Log.v("TAG", "listAdapter row " + i + "height:" + height);
totalHeight += height; // 统计所有子项的总高度
}
// 总高度 每个item总高度 + 子项间隔总和 +头部缩进 + 底部缩进
totalHeight = totalHeight
+ (getDividerHeight() * (listAdapter.getCount() - 1))
+ getPaddingBottom() + getPaddingTop();
// Log.v(TAG, "params.height" + params.height);
// // listView.getDividerHeight()获取子项间分隔符占用的高度
//
// // params.height最后得到整个ListView完整显示需要的高度
setMeasuredDimension(getMeasuredWidth(), totalHeight);
}
}
- 不滚动的listView(解决带head foot 计算)
- 让UIRTableView 的head和foot 不浮动在页面上
- php的head.php和foot.php
- 计算ListView滚动的距离
- 安卓listview 的.addFooterView(View foot)
- 设置不显示ListView的滚动条
- reactnative 解决listview无法滚动的问题
- 重新计算ListView的高度,解决ScrollView和ListView两个View都有滚动的效果,在嵌套使用时解决冲突的问题
- 对RecyclerView的ViewType的使用以及添加Foot和Head的心得
- ListView去掉自带的线条和滚动条
- ListView的横向滚动(带表头与固定列)
- Fixed Table Head Foot And the Left
- 计算Listview的高度解决Scrollview和listview的冲突
- android4.1+ ListView 不滚动
- android4.1+ ListView 不滚动
- android ListView 设置不滚动
- React-native ListView不滚动
- iframe 不带滚动条
- CStaticButton类
- windows下如何查看磁盘IO性能
- java获取中国城市代码 中国城市ID
- Emoji表情符号兼容方案
- 重新注册所有OCX和DLL
- 不滚动的listView(解决带head foot 计算)
- SSH整合,"sessionFactory " or "hibernateTemplate " is required异常
- 懒人懒到家 批量修改DB中字段类型
- 在iOS上实现二维码功能
- Oracle中的Package/Procedure/Function存放在哪里?
- 企业库EnterpriseLibrary学习笔记之--通过企业库Microsoft.Practices.EnterpriseLibrary,实现调用存储过程的封装
- 前台进程和后台进程
- Commons BeanUtils 1.8.3及以下版本的BUG
- java线程安全总结 (一)