【发布时间】:2015-05-06 09:25:28
【问题描述】:
如何在 android L 中创建一个项目列表,例如最近的应用程序列表:
【问题讨论】:
-
到目前为止你尝试了什么?向我们展示一些代码(和努力......) - 在我们可能无法为您提供太多帮助之前。
如何在 android L 中创建一个项目列表,例如最近的应用程序列表:
【问题讨论】:
这很简单:
实现布局。这部分是最困难的。屏幕上项目的位置是滚动+布局中的位置的非线性函数。基本上,您希望容器顶部的项目和 container.getHeight()-item.getHeight() 作为底部项目的位置接近于零。然后你必须找到一个适合你的功能。对我来说是这样的:
private void layoutChildren() {
int width = getWidth() - getPaddingLeft() - getPaddingRight();
int height = getHeight() - getPaddingTop() - getPaddingBottom();
for (int i = 0; i < getChildCount(); i++) {
float topSpace = height - width;
int y = (int) (topSpace * Math.pow(2, (i * width - scroll) / (float) width));
float scale = (float) (-Math.pow(2, -y / topSpace / 10.0f) + 19.0f / 10);
ViewHelper.setTranslationX(getChildAt(i), getPaddingLeft());
ViewHelper.setTranslationY(getChildAt(i), y + getPaddingTop());
ViewHelper.setScaleX(getChildAt(i), scale);
ViewHelper.setScaleY(getChildAt(i), scale);
}
}
更多细节和实现可以查看我的项目:
https://github.com/ZieIony/MaterialRecents
或者,如果您希望看到它的实际效果,它是 Carbon 库的一部分。您可以在小部件部分找到带有该 RecentsList 的示例应用程序:
【讨论】: