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);
}
}
分享到:
相关推荐
android 横向滚动listview,和自带的listview用法一致
通过焦点横向移动listview ,以及listview联动其它listview;[测试请用1280*720模拟器]
横向滚动的ListView,包含示例代码
c# listview 实现循环滚动显示
android demo,自定义支持横向滚动的ListView。android demo,自定义支持横向滚动的ListView。
android横向滚动listview
说明并罗列了解决快速滚动ListView造成黑色背景的问题
解决ScrollView ListView 滚动条冲突 ,其它带滚动条的控件一样适用 ,主要是固定内层控件的高度 达到可滑动的效果
[WPF]解决ListView在没有Items时,水平滚动条不出现的问题
ListView对应多个布局的实现方式。ListView滚动中布局错误的解决方案,博客中对于的介绍博文
横向滑动的ListView,你懂的很好的,跟自带的使用方式一样
效果不错的listview(带下拉刷新和加载更多,条目滚动带动画),效果很不错,值得一用,谁用谁知道
搜集整理 android可水平滚动的 ListView
知识点:1、解决listView滚动时checkBox的选择状态会发生变化(絮乱);2、ListView的Item长按,点击时间并存,实现同一UI控件多需求响应各类事件;3、点击ListViewItem选中响应Item里的CheckBox;4、计算选中的项数...
实现listview自动循环滚动
listview textview 水平滚动,用了Adapter,一次滚动两个textview
Android 实现ListView滚动到底部自动加载数据
监听listview垂直滚动的距离,listview item的高度相同不同都适用,博客地址 http://blog.csdn.net/brastom/article/details/50638274
Android支持横行滚动的ListView控件
listview自动滚动,对应效果:http://blog.csdn.net/nwsuafer/article/details/42873311