【问题标题】:How to create a list like "Recent apps list" in Android L [closed]如何在Android L中创建类似“最近的应用程序列表”的列表[关闭]
【发布时间】:2015-05-06 09:25:28
【问题描述】:

如何在 android L 中创建一个项目列表,例如最近的应用程序列表:

【问题讨论】:

  • 到目前为止你尝试了什么?向我们展示一些代码(和努力......) - 在我们可能无法为您提供太多帮助之前。

标签: android user-interface


【解决方案1】:

这很简单:

  • 从单个项目的布局开始。创建一个带有工具栏、图标、标题、[x] 按钮等的 xml。
  • 创建用于存放这些项目的布局。您可以从任何您希望的布局类开始 - FrameLayout 非常简单并且在这种情况下运行良好。
  • 实现将项目添加到您的容器。您可能需要使用适配器。在这种情况下,请查看 ListView 或类似的来源。
  • 实现手势检测。滚动非常简单,但您可能需要处理滑动手势以轻松关闭项目。查看任何滑动关闭库以了解更多详细信息。
  • 实现布局。这部分是最困难的。屏幕上项目的位置是滚动+布局中的位置的非线性函数。基本上,您希望容器顶部的项目和 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 的示例应用程序:

https://github.com/ZieIony/Carbon

【讨论】:

  • 我尝试使用库(MaterialRecents),但我更多地在横向实现它,在这种情况下,卡片的外观和特别的滑动动作有点颠倒(这在垂直方向上很好用)。您能否建议所需的更改?
  • @Zielony,这是我问你的同一个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多