其他分享
首页 > 其他分享> > 在StateListDrawable中将android:constantSize设置为’true’有什么好处?

在StateListDrawable中将android:constantSize设置为’true’有什么好处?

作者:互联网

如果您曾经不得不为Android创建自定义按钮,那么您将使用StateList Drawable;否则你应该有.现在,如果您看一下Android documentation for StatList Drawables,那么您将看到有一个名为“ android:constantSize”的选项,其行为如下:

Boolean. “true” if the drawable’s reported internal size remains constant as the state changes (the size is the maximum of all of the states); “false” if the size varies based on the current state. Default is false.

现在一切都很好.我认为这是在告诉我,如果图像的大小在任何状态下均未更改,则应将其设置为true.我的问题是:将此值设置为true有什么好处?它会加快渲染时间吗?在后台效率更高吗?

本质上,将此属性设置为true有什么好处?

解决方法:

设置标志后,drawable计算一次常量大小,并将其用于所有有关其大小的查询.如果未设置该标志,它将每次查询当前可绘制对象的固有宽度.

标签:performance,android-layout,android
来源: https://codeday.me/bug/20191201/2083984.html