【问题标题】:Android heterogeneous gridview like pinterest? [closed]像pinterest这样的Android异构gridview? [关闭]
【发布时间】:2012-07-31 09:07:31
【问题描述】:

是否可以使用GridView 在 Android 上创建类似 pinterest 的布局?我想使用GridView 创建图片库,但我不确定它是否是一个好的解决方案。我不想创建三个LinearLayouts(我认为这个解决方案不好:Pinterest style listview or gridview in android

有什么想法;)?

【问题讨论】:

  • 确定这是否是图片上的网格视图。
  • GridView 在这里不起作用,因为height 对于所有图像都不相同
  • 在我看来真的就像三列 imageViews。
  • 3 ListViews 可能会更好,因为您可以进行一些回收。但是,考虑到您可以独立滚动每一列,它也可能会导致不需要的 UI 行为。
  • 我认为最好的方法是创建自己的视图并自己处理绘制代码。

标签: java android pinterest


【解决方案1】:

我也一直在玩这个(使用 LinearLayout),但最后我遇到了很多内存消耗问题(尤其是当我不得不重新加载项目时)。我选择了简单的解决方案 使用两个同步的 ListViews。这样我可以利用内部缓存,这很有帮助。 为此,我必须使用同步列表的 OnTouchListenerOnScrollListener。 这是一个例子:

https://github.com/vladexologija/PinterestListView

【讨论】:

  • 你能发布这个示例代码吗?
  • 您到底需要什么?整个活动来源?
  • 实际上比上面的代码还要多。作为一名新手 android 开发人员,我需要一段时间才能掌握您提出的概念。
  • 你去。还有很多事情要做(修复一些错误,优化,简化......)但这个版本工作正常。它使用回收最重要的是什么!
  • @vladexogija 非常感谢您提供这么好的帖子。
【解决方案2】:

如下创建布局

<ScrollView...>
<LinearLayout....
   android:id="@+id/linear1"
   orientation="horizontal">

   <LinearLayout....
     android:id="@+id/linear2"
     android:layout_weight="0.33"
     orientation="vertical">

   <LinearLayout....
     android:id="@+id/linear3"
     android:layout_weight="0.33"
     orientation="vertical">

   <LinearLayout....
     android:layout_weight="0.33"
     orientation="vertical">

</LinearLayout>
</ScrollView>

现在在布局中动态添加您的ImageView

linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
linear3 = (LinearLayout) findViewById(R.id.linear3);

for(int i=0;i<n;i++)
{
   ImageView iv = new ImageView(this);
   iv.setImageResource(R.id.icon);

   int j = count % 3;  <---- 
   if(j==0)
       linear1.addView(iv);
   else if(j==1)
       linear2.addView(iv);
   else
       linear3.addView(iv); 
}

输出:

【讨论】:

  • 我知道这是可能的,但我不想使用 LinearyLayout,因为视图回收不好。此解决方案不适用于许多图像视图。
  • 如你所愿,但我已经这样做了,我正在从 URL 加载 120 张图片
  • 这是一个非常简洁的解决方案。
  • 它运行速度快且没有内存消耗问题吗?
  • 这个解决方案可以工作,但如果有很多项目,它可能会导致初始化缓慢和 OOM 。我已经添加了一个可能的解决方案,它使用了相同的适配器视图。
【解决方案3】:

【讨论】:

【解决方案4】:

对于这个问题的最近访问者,我建议使用RecyclerViewStaggedGridLayoutManager。它具有足够的功能和灵活性。

【讨论】:

    【解决方案5】:

    用于同步滚动 2 个 ListView 的独立助手:https://gist.github.com/yanchenko/6179793

    【讨论】:

      【解决方案6】:

      我正在使用这个库:https://github.com/huewu/PinterestLikeAdapterView

      效果很好。我唯一的问题是setOnItemClickListenersetOnItemLongClickListener 有点错误,所以我直接在convertView 上设置了监听器。

      【讨论】:

        【解决方案7】:

        这个库来自 Etsy 应用程序: https://github.com/etsy/AndroidStaggeredGrid

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-11
          • 2015-05-14
          • 2021-01-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多