我有一个自定义 listView,其中包含一个固定标题和 x 数量的“上推” View ,这些 View 可以上推并隐藏在 ListView 上方。
我附上图片来解释它们。抱歉“黑审查”,只是为了隐藏客户标志等。
我的问题是,如果我向固定的页眉 View 添加填充,我将得到 float 在它后面的 ListView 项目。
固定 header View 的实现方式与您在搜索 PinnedHeaderListView 时会发现的技术相同,即静态 View 和 ListView 中的 header 。
我找到了一种启用填充的方法,即通过将与固定标题相同的填充应用于实际的 listView,但仅当静态标题可见时。
但是,调用 setPadding 会导致非常明显的 Jank,我想将其删除。 有谁知道如何消除这个卡顿?
我有一个带有简单 View 和虚拟数据的简单应用程序,它没有显示此卡顿,因此卡顿的数量可能取决于单元格布局的复杂性。
private void updateIfShouldShowStaticHeaderView() {
//unfortunately setting the padding of the listView causes JANK.
//any ideas?
int bottomOfFloatingHeader = floatingHeader.getBottom();
if (bottomOfFloatingHeader < mHeaderViewHeight) {
staticHeaderViewIsVisible = true;
staticHeader.setVisibility(View.VISIBLE);
//need to set padding of listView to avoid having list-view items float behind my padded static header
setPadding(0, staticHeader.getPaddingTop(), 0, getPaddingBottom());
} else {
staticHeaderViewIsVisible = false;
staticHeader.setVisibility(View.INVISIBLE);
//need to set padding of listView to avoid having list-view items float behind my padded static header
setPadding(0, 0, 0, getPaddingBottom());
}
}
首先是显示上推标题的图片
这是一张图片,显示了如何在填充的静态固定 View 后面绘制内容。 值得注意的是,如果我调整 listView 的填充,它会按预期工作,但在它打开/关闭静态标题 View 时,我会得到 Jank (slowdown) 。
最佳答案
需要有关您的问题的更多信息。
据我了解,Jank 是由于您使用的大量数据和可绘制对象造成的。
尝试为您的 View 启用硬件加速。
有关硬件加速的更多信息,请尝试此 http://developer.android.com/guide/topics/graphics/hardware-accel.html
关于android - 带有 Pinned Header 的自定义 ListView,在设置 padding 时导致 Jank,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11452130/