android联系人源码解析
来源:互联网 发布:js ajax 登录验证 编辑:程序博客网 时间:2024/06/05 16:30
转载请注明出处:http://blog.csdn.net/droyon/article/details/9102797
源代码请从官方网站下载,本文针对源代码增加上自己的理解。
- package com.android.contacts.widget;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.widget.ListView;
- /**
- * A ListView that can be asked to scroll (smoothly or otherwise) to a specific
- * position. This class takes advantage of similar functionality that exists
- * in {@link ListView} and enhances it.
- * <strong><span style="color:#ff0000;">联系人应用中自定义组件,增强了ListView的功能。
- * 用于滑动到某一个位置 以及 在到达某个位置时是否平滑</span></strong>
- */
- public class AutoScrollListView extends ListView {
- /**
- * Position the element at about 1/3 of the list height
- */
- private static final float PREFERRED_SELECTION_OFFSET_FROM_TOP = 0.33f;
- private int mRequestedScrollPosition = -1;
- private boolean mSmoothScrollRequested;
- public AutoScrollListView(Context context) {
- super(context);
- }
- public AutoScrollListView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public AutoScrollListView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- /**
- * Brings the specified position to view by optionally performing a jump-scroll maneuver:
- * first it jumps to some position near the one requested and then does a smooth
- * scroll to the requested position. This creates an impression of full smooth
- * scrolling without actually traversing the entire list. If smooth scrolling is
- * not requested, instantly positions the requested item at a preferred offset.
- * <strong><span style="color:#006600;">提供的一个方法,是否平滑滑动到position处</span></strong>
- */
- public void requestPositionToScreen(int position, boolean smoothScroll) {
- mRequestedScrollPosition = position;
- mSmoothScrollRequested = smoothScroll;
- requestLayout();
- }
- <strong><span style="color:#006600;"> /**
- * 这个方法在ListView(ListView包含了一系列的Item【项】)中用于布局ListViewItem。
- */</span></strong>
- @Override
- protected void layoutChildren() {<strong><span style="color:#006600;">//重写的ListView中的方法,这个方法,主要就是封装了ListView中的layoutChildren。</span></strong>
- super.layoutChildren();
- if (mRequestedScrollPosition == -1) {
- return;
- }
- final int position = mRequestedScrollPosition;
- mRequestedScrollPosition = -1;
- int firstPosition = getFirstVisiblePosition() + 1;
- int lastPosition = getLastVisiblePosition();
- if (position >= firstPosition && position <= lastPosition) {
- return; // Already on screen
- }
- final int offset = (int) (getHeight() * PREFERRED_SELECTION_OFFSET_FROM_TOP);
- if (!mSmoothScrollRequested) {
- setSelectionFromTop(position, offset);
- // Since we have changed the scrolling position, we need to redo child layout
- // Calling "requestLayout" in the middle of a layout pass has no effect,
- // so we call layoutChildren explicitly
- <strong><span style="color:#006600;">//如果不需要平滑的滑动到position处,直接调用父类的layoutChildren方法。</span></strong>
- super.layoutChildren();
- } else {
- // We will first position the list a couple of screens before or after
- // the new selection and then scroll smoothly to it.
- <strong><span style="color:#006600;">//现在是处理平滑滑动到某个位置了,如何处理那?
- //我们首先需要将当前的list条目焦点设定在离要滑动的位置2屏内。为什么这么处理那?
- //设想一下,list有1000个条目,一屏可以存放10条条目,我们当前处在最后一屏(也就是当前显示990~1000),那么我们要平滑滑动的位置为1
- //我们的listView要从990一直平滑滑动到1,这要多费功夫,
- //所以,直接把焦点设定在list的20处(2屏数目),然后从20位置平滑过度到1。</span></strong>
- int twoScreens = (lastPosition - firstPosition) * 2;
- int preliminaryPosition;
- if (position < firstPosition) {
- preliminaryPosition = position + twoScreens;
- if (preliminaryPosition >= getCount()) {
- preliminaryPosition = getCount() - 1;
- }
- if (preliminaryPosition < firstPosition) {
- setSelection(preliminaryPosition);
- super.layoutChildren();
- }
- } else {
- preliminaryPosition = position - twoScreens;
- if (preliminaryPosition < 0) {
- preliminaryPosition = 0;
- }
- if (preliminaryPosition > lastPosition) {
- setSelection(preliminaryPosition);
- super.layoutChildren();
- }
- }
- smoothScrollToPositionFromTop(position, offset);
- }
- }
- }
- android联系人源码解析
- android联系人源码解析
- Android contacts 联系人 通讯录 源码 完全解析
- Android contacts 联系人 通讯录 源码 完全解析
- Android contacts 联系人 通讯录 源码 完全解析
- Android仿联系人列表分组悬浮列表,PinnedHeaderListView源码解析
- android 合并联系人。。。。源码
- Android 联系人 数据库解析
- Android Contacts 联系人源码分析
- Android Contacts 联系人源码分析
- Android Contacts 联系人源码分析
- android4.0联系人添加的源码解析
- Android手机联系人源码(添加联系人页面一个功能)修改
- Android联系人数据库全解析(1)
- Android联系人数据库全解析(2)
- Android联系人数据库全解析(1)
- Android联系人数据库全解析(1)
- Android联系人数据库全解析(1)
- Java中HashMap遍历的两种方式
- 在objective-c中解析html
- ASP.NET 4.5 MVC4.0
- gdb调试命令小结_与多文件调试_远程调试
- 获取程序当前目录的方法
- android联系人源码解析
- 机器学习相关——协同过滤
- c++ 使用throw抛出异常
- -bash: ulimit: pipe size: cannot modify limit: Invalid argument
- WEB开发各种问题及解决方法汇总
- 数据分析师常见的10道面试题解答
- 推荐系统的常用算法概述
- VS2010设置
- 编程名言名句