java-在Android中管理View重用的代码在哪里?

Android中管理View重用的源代码在哪里?我可以想到此过程的三个不同部分,但可能还有更多:

>确定视图是否符合重用条件的逻辑
>管理可重复使用的视图池的代码
>从池中删除可重复使用的View并重置其属性值以表示逻辑上不同的View的代码

编辑:博客文章Developing applications for Android – gotchas and quirks给出了以下示例:

public class PencilWise extends ListActivity {
    View activeElement;
    // ...
    @Override
    public void onCreate ( Bundle savedInstanceState ) {
        // ...
        this.getListView( ).setonItemClickListener ( new OnItemClickListener ( ) {
            public void onItemClick ( AdapterView<?> parent, View view, int position, long id ) {
                MyActivity.this.activeElement = view;
                MyActivity.this.showDialog ( DIALOG_ANSWER );
            }
        } );
    }
}

The showDialog method will display the answer dialog, which needs to kNow what question the user has opened. The problem is that by the time the dialog opens, the view passed to onItemClick might have been reused, and so activeElement would no longer point to the element the user clicked to open the dialog in the first place!

解决方法:

我认为您正在寻找的一个很好的例子是在widget包中的AbsListView.RecycleBin内部类中.
您可以在此处在线查看代码
https://android.googlesource.com/platform/frameworks/base/+/android-2.2_r1.1/core/java/android/widget/AbsListView.java#3888

以下是文档摘录:

The RecycleBin facilitates reuse of views across layouts. The RecycleBin has two levels of
storage: ActiveViews and ScrapViews. ActiveViews are those views which were onscreen at the
start of a layout. By construction, they are displaying current information. At the end of
layout, all views in ActiveViews are demoted to ScrapViews. ScrapViews are old views that
Could potentially be used by the adapter to avoid allocating views unnecessarily.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...