如果我有一个简单的自定义视图:
myitem.xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<FrameLayout/>
访问 kotlinx syntentic 属性:
import kotlinx.android.synthetic.main.myitem.view.*
view.toolbar.text = "Some text"
它在内部生成一个调用findByViewID()
。所以我的问题是:
是否为自定义视图(例如活动或每次)缓存结果findByViewID
叫做?出于性能原因,答案非常重要。
在当前版本(1.1.3)中,视图被缓存以用于活动和片段布局。对于其他类型的容器(例如 RecyclerView ViewHolders),没有缓存。
另外,缓存是一个HashMap
键的整数装箱。 ASparseArray
会更好。
编辑:从版本 1.1.4 开始,视图也可以缓存其他类,包括ViewHolder
,如果你让他们实施LayoutContainer
界面。您还可以使用@ContainerOptions
注解指定另一个缓存实现,包括SparseArray
。这两个功能仍处于实验阶段,需要在您的系统中手动启用build.gradle
file:
androidExtensions {
experimental = true
}
阅读更多 https://github.com/Kotlin/KEEP/blob/master/proposals/android-extensions-entity-caching.md关于它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)