关于listview
来源:互联网 发布:淘宝客教程全集 编辑:程序博客网 时间:2024/06/07 03:04
1、listview 设置stackFromBottom="true" 这个属性以后,item会从底部向顶部 排列,
/**
* Make sure views are touching the top or bottom edge, as appropriate for
* our gravity
*/
private void adjustViewsUpOrDown() {
final int childCount = getChildCount();
int delta;
if (childCount > 0) {
View child;
if (!mStackFromBottom) {
// Uh-oh -- we came up short. Slide all views up to make them
// align with the top
child = getChildAt(0);
delta = child.getTop() - mListPadding.top;
if (mFirstPosition != 0) {
// It's OK to have some space above the first item if it is
// part of the vertical spacing
delta -= mDividerHeight;
}
if (delta < 0) {
// We only are looking to see if we are too low, not too high
delta = 0;
}
} else {
// we are too high, slide all views down to align with bottom
child = getChildAt(childCount - 1);
delta = child.getBottom() - (getHeight() - mListPadding.bottom);
if (mFirstPosition + childCount < mItemCount) {
// It's OK to have some space below the last item if it is
// part of the vertical spacing
delta += mDividerHeight;
}
if (delta > 0) {
delta = 0;
}
}
if (delta != 0) {
offsetChildrenTopAndBottom(-delta);
}
}
}
最后到了viewgroup里边 调用的这个方法
public void offsetChildrenTopAndBottom(int offset) {
final int count = mChildrenCount;
final View[] children = mChildren;
for (int i = 0; i < count; i++) {
final View v = children[i];
v.mTop += offset;
v.mBottom += offset;
}
}
重新设置位置
2、关于 addHeadView
代码445行
if (mHeaderViewInfos.size() > 0|| mFooterViewInfos.size() > 0) {
mAdapter = new HeaderViewListAdapter(mHeaderViewInfos, mFooterViewInfos, adapter);
} else {
mAdapter = adapter;
}
如果有headview或者footview,就会用HeaderViewListAdapter去包装我们设置的adapter。
看他的getCount方法
public int getCount() {
if (mAdapter != null) {
return getFootersCount() + getHeadersCount() + mAdapter.getCount();
} else {
return getFootersCount() + getHeadersCount();
}
}
设置onitemclicklistener以后
private class PerformClick extends WindowRunnnable implements Runnable {
int mClickMotionPosition;
public void run() {
// The data has changed since we posted this action in the event queue,
// bail out before bad things happen
if (mDataChanged) return;
final ListAdapter adapter = mAdapter;
final int motionPosition = mClickMotionPosition;
if (adapter != null && mItemCount > 0 &&
motionPosition != INVALID_POSITION &&
motionPosition < adapter.getCount() && sameWindow()) {
final View view = getChildAt(motionPosition - mFirstPosition);
// If there is no view, something bad happened (the view scrolled off the
// screen, etc.) and we should cancel the click
if (view != null) {
performItemClick(view, motionPosition, adapter.getItemId(motionPosition));
}
}
}
}
如果 有head或者footer,mAdapter 就是HeaderViewListAdapter,所以,onitemclicklistener 这里可以得到head或者footer的点击事件。
- 关于listview嵌套listview
- 关于listview
- 关于ListView
- 关于listView
- 关于listview
- 关于ListView
- 关于listview内嵌套listview
- 关于数据库连接(datagrid,listview)
- 关于 ListView layout_width
- 关于ListView的使用
- 关于ListView的用法
- 关于listview 背景图片变黑
- 关于ListView和Adapter
- 关于 ListView 缓存优化
- 关于自定义ListView
- 关于Android的ListView
- 关于ListView的注意事项
- 关于ListView优化
- Filezilla项目发布地址
- js格式化日期字符串进行时间比较
- iOS学习之 plist文件的读写
- HDU_1166 地兵布阵
- Android SDK Android NDK Android Studio 官方下载地址
- 关于listview
- POJ 1094 Sorting It All Out 拓扑排序
- vim中文乱码解决办法
- vi文字处理器
- pandaboard Es Rev b3 刷android4.2
- 第十周项目三血型统计
- 黑马程序员————小牛皮糖学习笔记————IO流之未使用缓冲区读写文件
- jQuery中Ajax工具函数使用1
- java泛型(三)、通配符的使用